blob: 51fd07f699d69f18dc07929cb6b52237c75b7568 [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 Bonadei254ecff2019-01-16 12:14:29 +010013#include "absl/strings/string_view.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#include "rtc_base/arraysize.h"
deadbeef6038e972017-02-16 23:31:33 -080015
16namespace {
17
Mirko Bonadei254ecff2019-01-16 12:14:29 +010018const absl::string_view kRTCErrorTypeNames[] = {
deadbeef6038e972017-02-16 23:31:33 -080019 "NONE",
20 "UNSUPPORTED_OPERATION",
21 "UNSUPPORTED_PARAMETER",
22 "INVALID_PARAMETER",
23 "INVALID_RANGE",
24 "SYNTAX_ERROR",
25 "INVALID_STATE",
26 "INVALID_MODIFICATION",
27 "NETWORK_ERROR",
28 "RESOURCE_EXHAUSTED",
29 "INTERNAL_ERROR",
30};
31static_assert(static_cast<int>(webrtc::RTCErrorType::INTERNAL_ERROR) ==
32 (arraysize(kRTCErrorTypeNames) - 1),
33 "kRTCErrorTypeNames must have as many strings as RTCErrorType "
34 "has values.");
35
36} // namespace
37
38namespace webrtc {
39
Jonas Olsson941a07c2018-09-13 10:07:07 +020040RTCError::RTCError(RTCError&& other) = default;
41RTCError& RTCError::operator=(RTCError&& other) = default;
deadbeef6038e972017-02-16 23:31:33 -080042
43// static
44RTCError RTCError::OK() {
45 return RTCError();
46}
47
48const char* RTCError::message() const {
Jonas Olsson941a07c2018-09-13 10:07:07 +020049 return message_.c_str();
deadbeef6038e972017-02-16 23:31:33 -080050}
51
Jonas Olsson941a07c2018-09-13 10:07:07 +020052void RTCError::set_message(std::string message) {
53 message_ = std::move(message);
deadbeef6038e972017-02-16 23:31:33 -080054}
55
Mirko Bonadei254ecff2019-01-16 12:14:29 +010056absl::string_view ToString(RTCErrorType error) {
deadbeef6038e972017-02-16 23:31:33 -080057 int index = static_cast<int>(error);
Mirko Bonadei254ecff2019-01-16 12:14:29 +010058 return kRTCErrorTypeNames[index];
deadbeef6038e972017-02-16 23:31:33 -080059}
60
61} // namespace webrtc