blob: 0aa4304386fd0a3fa31c0f93e9e8f473070e2a48 [file] [log] [blame]
deadbeef6038e972017-02-17 07:31:331/*
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 Anton10542f22019-01-11 17:11:0011#include "api/rtc_error.h"
deadbeef6038e972017-02-17 07:31:3312
Danil Chapovalova2d85e42023-03-20 16:37:2213#include <iterator>
14
15#include "absl/strings/string_view.h"
deadbeef6038e972017-02-17 07:31:3316
17namespace {
18
Danil Chapovalova2d85e42023-03-20 16:37:2219absl::string_view kRTCErrorTypeNames[] = {
deadbeef6038e972017-02-17 07:31:3320 "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 Alvestranddfbfb462019-12-08 04:55:4331 "OPERATION_ERROR_WITH_DATA",
deadbeef6038e972017-02-17 07:31:3332};
Harald Alvestranddfbfb462019-12-08 04:55:4333static_assert(
34 static_cast<int>(webrtc::RTCErrorType::OPERATION_ERROR_WITH_DATA) ==
Danil Chapovalova2d85e42023-03-20 16:37:2235 (std::size(kRTCErrorTypeNames) - 1),
Harald Alvestranddfbfb462019-12-08 04:55:4336 "kRTCErrorTypeNames must have as many strings as RTCErrorType "
37 "has values.");
38
Danil Chapovalova2d85e42023-03-20 16:37:2239absl::string_view kRTCErrorDetailTypeNames[] = {
Harald Alvestranddfbfb462019-12-08 04:55:4340 "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};
49static_assert(
50 static_cast<int>(webrtc::RTCErrorDetailType::HARDWARE_ENCODER_ERROR) ==
Danil Chapovalova2d85e42023-03-20 16:37:2251 (std::size(kRTCErrorDetailTypeNames) - 1),
Harald Alvestranddfbfb462019-12-08 04:55:4352 "kRTCErrorDetailTypeNames must have as many strings as "
53 "RTCErrorDetailType has values.");
deadbeef6038e972017-02-17 07:31:3354
55} // namespace
56
57namespace webrtc {
58
deadbeef6038e972017-02-17 07:31:3359// static
60RTCError RTCError::OK() {
61 return RTCError();
62}
63
64const char* RTCError::message() const {
Jonas Olsson941a07c2018-09-13 08:07:0765 return message_.c_str();
deadbeef6038e972017-02-17 07:31:3366}
67
Danil Chapovalova2d85e42023-03-20 16:37:2268void RTCError::set_message(absl::string_view message) {
69 message_ = std::string(message);
deadbeef6038e972017-02-17 07:31:3370}
71
Danil Chapovalova2d85e42023-03-20 16:37:2272absl::string_view ToString(RTCErrorType error) {
deadbeef6038e972017-02-17 07:31:3373 int index = static_cast<int>(error);
Mirko Bonadei254ecff2019-01-16 11:14:2974 return kRTCErrorTypeNames[index];
deadbeef6038e972017-02-17 07:31:3375}
76
Danil Chapovalova2d85e42023-03-20 16:37:2277absl::string_view ToString(RTCErrorDetailType error) {
Harald Alvestranddfbfb462019-12-08 04:55:4378 int index = static_cast<int>(error);
79 return kRTCErrorDetailTypeNames[index];
80}
81
deadbeef6038e972017-02-17 07:31:3382} // namespace webrtc