blob: c9ad7cb634539fcf6fc1c71fc792eefabd546e8e [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",
29};
30static_assert(static_cast<int>(webrtc::RTCErrorType::INTERNAL_ERROR) ==
31 (arraysize(kRTCErrorTypeNames) - 1),
32 "kRTCErrorTypeNames must have as many strings as RTCErrorType "
33 "has values.");
34
35} // namespace
36
37namespace webrtc {
38
Jonas Olsson941a07c2018-09-13 10:07:07 +020039RTCError::RTCError(RTCError&& other) = default;
40RTCError& RTCError::operator=(RTCError&& other) = default;
deadbeef6038e972017-02-16 23:31:33 -080041
42// static
43RTCError RTCError::OK() {
44 return RTCError();
45}
46
47const char* RTCError::message() const {
Jonas Olsson941a07c2018-09-13 10:07:07 +020048 return message_.c_str();
deadbeef6038e972017-02-16 23:31:33 -080049}
50
Jonas Olsson941a07c2018-09-13 10:07:07 +020051void RTCError::set_message(std::string message) {
52 message_ = std::move(message);
deadbeef6038e972017-02-16 23:31:33 -080053}
54
Mirko Bonadeifb59a6a2019-09-20 09:33:02 +020055const char* ToString(RTCErrorType error) {
deadbeef6038e972017-02-16 23:31:33 -080056 int index = static_cast<int>(error);
Mirko Bonadei254ecff2019-01-16 12:14:29 +010057 return kRTCErrorTypeNames[index];
deadbeef6038e972017-02-16 23:31:33 -080058}
59
60} // namespace webrtc