deadbeef | 6038e97 | 2017-02-17 07:31:33 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 11 | #include "api/rtc_error.h" |
deadbeef | 6038e97 | 2017-02-17 07:31:33 | [diff] [blame] | 12 | |
Danil Chapovalov | a2d85e4 | 2023-03-20 16:37:22 | [diff] [blame] | 13 | #include <iterator> |
| 14 | |
| 15 | #include "absl/strings/string_view.h" |
deadbeef | 6038e97 | 2017-02-17 07:31:33 | [diff] [blame] | 16 | |
| 17 | namespace { |
| 18 | |
Danil Chapovalov | a2d85e4 | 2023-03-20 16:37:22 | [diff] [blame] | 19 | absl::string_view kRTCErrorTypeNames[] = { |
deadbeef | 6038e97 | 2017-02-17 07:31:33 | [diff] [blame] | 20 | "NONE", |
| 21 | "UNSUPPORTED_OPERATION", |
| 22 | "UNSUPPORTED_PARAMETER", |
| 23 | "INVALID_PARAMETER", |
| 24 | "INVALID_RANGE", |
| 25 | "SYNTAX_ERROR", |
| 26 | "INVALID_STATE", |
| 27 | "INVALID_MODIFICATION", |
| 28 | "NETWORK_ERROR", |
| 29 | "RESOURCE_EXHAUSTED", |
| 30 | "INTERNAL_ERROR", |
Harald Alvestrand | dfbfb46 | 2019-12-08 04:55:43 | [diff] [blame] | 31 | "OPERATION_ERROR_WITH_DATA", |
deadbeef | 6038e97 | 2017-02-17 07:31:33 | [diff] [blame] | 32 | }; |
Harald Alvestrand | dfbfb46 | 2019-12-08 04:55:43 | [diff] [blame] | 33 | static_assert( |
| 34 | static_cast<int>(webrtc::RTCErrorType::OPERATION_ERROR_WITH_DATA) == |
Danil Chapovalov | a2d85e4 | 2023-03-20 16:37:22 | [diff] [blame] | 35 | (std::size(kRTCErrorTypeNames) - 1), |
Harald Alvestrand | dfbfb46 | 2019-12-08 04:55:43 | [diff] [blame] | 36 | "kRTCErrorTypeNames must have as many strings as RTCErrorType " |
| 37 | "has values."); |
| 38 | |
Danil Chapovalov | a2d85e4 | 2023-03-20 16:37:22 | [diff] [blame] | 39 | absl::string_view kRTCErrorDetailTypeNames[] = { |
Harald Alvestrand | dfbfb46 | 2019-12-08 04:55:43 | [diff] [blame] | 40 | "NONE", |
| 41 | "DATA_CHANNEL_FAILURE", |
| 42 | "DTLS_FAILURE", |
| 43 | "FINGERPRINT_FAILURE", |
| 44 | "SCTP_FAILURE", |
| 45 | "SDP_SYNTAX_ERROR", |
| 46 | "HARDWARE_ENCODER_NOT_AVAILABLE", |
| 47 | "HARDWARE_ENCODER_ERROR", |
| 48 | }; |
| 49 | static_assert( |
| 50 | static_cast<int>(webrtc::RTCErrorDetailType::HARDWARE_ENCODER_ERROR) == |
Danil Chapovalov | a2d85e4 | 2023-03-20 16:37:22 | [diff] [blame] | 51 | (std::size(kRTCErrorDetailTypeNames) - 1), |
Harald Alvestrand | dfbfb46 | 2019-12-08 04:55:43 | [diff] [blame] | 52 | "kRTCErrorDetailTypeNames must have as many strings as " |
| 53 | "RTCErrorDetailType has values."); |
deadbeef | 6038e97 | 2017-02-17 07:31:33 | [diff] [blame] | 54 | |
| 55 | } // namespace |
| 56 | |
| 57 | namespace webrtc { |
| 58 | |
deadbeef | 6038e97 | 2017-02-17 07:31:33 | [diff] [blame] | 59 | // static |
| 60 | RTCError RTCError::OK() { |
| 61 | return RTCError(); |
| 62 | } |
| 63 | |
| 64 | const char* RTCError::message() const { |
Jonas Olsson | 941a07c | 2018-09-13 08:07:07 | [diff] [blame] | 65 | return message_.c_str(); |
deadbeef | 6038e97 | 2017-02-17 07:31:33 | [diff] [blame] | 66 | } |
| 67 | |
Danil Chapovalov | a2d85e4 | 2023-03-20 16:37:22 | [diff] [blame] | 68 | void RTCError::set_message(absl::string_view message) { |
| 69 | message_ = std::string(message); |
deadbeef | 6038e97 | 2017-02-17 07:31:33 | [diff] [blame] | 70 | } |
| 71 | |
Danil Chapovalov | a2d85e4 | 2023-03-20 16:37:22 | [diff] [blame] | 72 | absl::string_view ToString(RTCErrorType error) { |
deadbeef | 6038e97 | 2017-02-17 07:31:33 | [diff] [blame] | 73 | int index = static_cast<int>(error); |
Mirko Bonadei | 254ecff | 2019-01-16 11:14:29 | [diff] [blame] | 74 | return kRTCErrorTypeNames[index]; |
deadbeef | 6038e97 | 2017-02-17 07:31:33 | [diff] [blame] | 75 | } |
| 76 | |
Danil Chapovalov | a2d85e4 | 2023-03-20 16:37:22 | [diff] [blame] | 77 | absl::string_view ToString(RTCErrorDetailType error) { |
Harald Alvestrand | dfbfb46 | 2019-12-08 04:55:43 | [diff] [blame] | 78 | int index = static_cast<int>(error); |
| 79 | return kRTCErrorDetailTypeNames[index]; |
| 80 | } |
| 81 | |
deadbeef | 6038e97 | 2017-02-17 07:31:33 | [diff] [blame] | 82 | } // namespace webrtc |