blob: 039e7f340aff5ab8cdf8427d5f9883da24f4bf07 [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
Mirko Bonadei92ea95e2017-09-15 04:47:3111#include "api/rtcerror.h"
deadbeef6038e972017-02-17 07:31:3312
Mirko Bonadei92ea95e2017-09-15 04:47:3113#include "rtc_base/arraysize.h"
deadbeef6038e972017-02-17 07:31:3314
15namespace {
16
17static const char* const kRTCErrorTypeNames[] = {
18 "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 08:07:0739RTCError::RTCError(RTCError&& other) = default;
40RTCError& RTCError::operator=(RTCError&& other) = default;
deadbeef6038e972017-02-17 07:31:3341
42// static
43RTCError RTCError::OK() {
44 return RTCError();
45}
46
47const char* RTCError::message() const {
Jonas Olsson941a07c2018-09-13 08:07:0748 return message_.c_str();
deadbeef6038e972017-02-17 07:31:3349}
50
Jonas Olsson941a07c2018-09-13 08:07:0751void RTCError::set_message(std::string message) {
52 message_ = std::move(message);
deadbeef6038e972017-02-17 07:31:3353}
54
Jonas Olsson74395342018-04-03 10:22:0755// TODO(jonasolsson): Change to use absl::string_view when it's available.
56std::string ToString(RTCErrorType error) {
deadbeef6038e972017-02-17 07:31:3357 int index = static_cast<int>(error);
Jonas Olsson74395342018-04-03 10:22:0758 return std::string(kRTCErrorTypeNames[index]);
deadbeef6038e972017-02-17 07:31:3359}
60
61} // namespace webrtc