blob: 4d3033baf58136969b6cb9702ae5c1280fd9182f [file] [log] [blame]
deadbeef6038e972017-02-16 23:31:33 -08001/*
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 09:11:00 -080011#include "api/rtc_error.h"
deadbeef6038e972017-02-16 23:31:33 -080012
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020013#include "rtc_base/arraysize.h"
deadbeef6038e972017-02-16 23:31:33 -080014
15namespace {
16
Mirko Bonadeifb59a6a2019-09-20 09:33:02 +020017const char* kRTCErrorTypeNames[] = {
deadbeef6038e972017-02-16 23:31:33 -080018 "NONE",
19 "UNSUPPORTED_OPERATION",
20 "UNSUPPORTED_PARAMETER",
21 "INVALID_PARAMETER",
22 "INVALID_RANGE",
23 "SYNTAX_ERROR",
24 "INVALID_STATE",
25 "INVALID_MODIFICATION",
26 "NETWORK_ERROR",
27 "RESOURCE_EXHAUSTED",
28 "INTERNAL_ERROR",
Harald Alvestranddfbfb462019-12-08 05:55:43 +010029 "OPERATION_ERROR_WITH_DATA",
deadbeef6038e972017-02-16 23:31:33 -080030};
Harald Alvestranddfbfb462019-12-08 05:55:43 +010031static_assert(
32 static_cast<int>(webrtc::RTCErrorType::OPERATION_ERROR_WITH_DATA) ==
33 (arraysize(kRTCErrorTypeNames) - 1),
34 "kRTCErrorTypeNames must have as many strings as RTCErrorType "
35 "has values.");
36
37const char* kRTCErrorDetailTypeNames[] = {
38 "NONE",
39 "DATA_CHANNEL_FAILURE",
40 "DTLS_FAILURE",
41 "FINGERPRINT_FAILURE",
42 "SCTP_FAILURE",
43 "SDP_SYNTAX_ERROR",
44 "HARDWARE_ENCODER_NOT_AVAILABLE",
45 "HARDWARE_ENCODER_ERROR",
46};
47static_assert(
48 static_cast<int>(webrtc::RTCErrorDetailType::HARDWARE_ENCODER_ERROR) ==
49 (arraysize(kRTCErrorDetailTypeNames) - 1),
50 "kRTCErrorDetailTypeNames must have as many strings as "
51 "RTCErrorDetailType has values.");
deadbeef6038e972017-02-16 23:31:33 -080052
53} // namespace
54
55namespace webrtc {
56
deadbeef6038e972017-02-16 23:31:33 -080057// static
58RTCError RTCError::OK() {
59 return RTCError();
60}
61
62const char* RTCError::message() const {
Jonas Olsson941a07c2018-09-13 10:07:07 +020063 return message_.c_str();
deadbeef6038e972017-02-16 23:31:33 -080064}
65
Jonas Olsson941a07c2018-09-13 10:07:07 +020066void RTCError::set_message(std::string message) {
67 message_ = std::move(message);
deadbeef6038e972017-02-16 23:31:33 -080068}
69
Mirko Bonadeifb59a6a2019-09-20 09:33:02 +020070const char* ToString(RTCErrorType error) {
deadbeef6038e972017-02-16 23:31:33 -080071 int index = static_cast<int>(error);
Mirko Bonadei254ecff2019-01-16 12:14:29 +010072 return kRTCErrorTypeNames[index];
deadbeef6038e972017-02-16 23:31:33 -080073}
74
Harald Alvestranddfbfb462019-12-08 05:55:43 +010075const char* ToString(RTCErrorDetailType error) {
76 int index = static_cast<int>(error);
77 return kRTCErrorDetailTypeNames[index];
78}
79
deadbeef6038e972017-02-16 23:31:33 -080080} // namespace webrtc