Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(751)

Side by Side Diff: webrtc/api/rtcerror.cc

Issue 2692723002: Adding RTCErrorOr class to be used by ORTC APIs. (Closed)
Patch Set: Updates based on tommi's comments Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
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
11 #include "webrtc/api/rtcerror.h"
12
13 #include "webrtc/base/arraysize.h"
14
15 namespace {
16
17 static 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 };
30 static_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
37 namespace webrtc {
38
39 // static
40 const RTCError& RTCError::OK() {
41 static RTCError ok;
42 return ok;
43 }
44
45 std::ostream& operator<<(std::ostream& stream, RTCErrorType error) {
46 int index = static_cast<int>(error);
47 return stream << kRTCErrorTypeNames[index];
48 }
49
50 webrtc::RTCError CreateAndLogError(webrtc::RTCErrorType type,
51 const std::string& message,
52 rtc::LoggingSeverity severity) {
53 // "No error" shouldn't be logged as an error.
54 RTC_DCHECK(type != RTCErrorType::NONE);
55 rtc::LogMessage(__FILE__, __LINE__, severity).stream() << message << " ("
56 << type << ")";
57 return webrtc::RTCError(type, message);
58 }
59
60 webrtc::RTCError CreateAndLogError(webrtc::RTCErrorType type,
61 const std::string& message) {
62 return CreateAndLogError(type, message, rtc::LS_ERROR);
63 }
64
65 } // namespace webrtc
OLDNEW
« webrtc/api/rtcerror.h ('K') | « webrtc/api/rtcerror.h ('k') | webrtc/pc/peerconnection.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698