MillicastSDK 2.0.0
Loading...
Searching...
No Matches
error.h
Go to the documentation of this file.
1#pragma once
2
4
5#include <system_error>
6
7namespace millicast {
16class MILLICAST_API Error : public std::error_condition {
17 public:
18 Error() = default;
19 Error(Error&&) noexcept = default;
20 Error(const Error&) = default;
21 Error& operator=(Error&&) noexcept = default;
22 Error& operator=(const Error&) = default;
23 Error(int val, const std::error_category& cat) noexcept;
24 Error(int val,
25 const std::error_category& cat,
26 const std::string& error_reason);
27 Error(const std::exception_ptr& exception) noexcept;
28
29 template <
30 typename EnumT,
31 typename X =
32 std::enable_if_t<std::is_error_condition_enum<EnumT>::value, void>>
33 Error(EnumT value) : Error(make_error_condition(value)) {}
34
35 template <
36 typename EnumT,
37 typename X =
38 std::enable_if_t<std::is_error_condition_enum<EnumT>::value, void>>
39 Error(EnumT value, const std::string& reason)
40 : Error(make_error_condition(value, reason)) {}
41
42 template <
43 typename EnumT,
44 typename X =
45 std::enable_if_t<std::is_error_condition_enum<EnumT>::value, void>>
46 bool operator==(EnumT val) const {
47 return make_error_condition(val) == *this;
48 }
49
54 [[nodiscard]] const std::string& message() const { return _message; }
55
56 private:
57 std::string _message{};
58};
59
66template <typename T>
67struct MILLICAST_TEMPLATE_API ErrorCategoryBase : public std::error_category {
68 static const T& instance() {
69 static T inst;
70 return inst;
71 }
72};
73
79 : public ErrorCategoryBase<AsyncOperationCancelled> {
80 public:
81 enum Value {
82 MULTIPLE_RESOLVE = 1,
83 ABORTED,
86 ACTOR_SHUTDOWN,
89 };
90
91 [[nodiscard]] const char* name() const noexcept override;
92 [[nodiscard]] std::string message(int ev) const override;
93};
94
99 public:
100 enum Value {
101 EXCEPTION_THROWN = 1,
103 INVALID_JSON_SCHEMA,
113 PEERCONNECTION_LOCAL_DESC,
115 PEERCONNECTION_REMOTE_DESC,
119 PEERCONNECTION_SET_TRANSFORM_FAILED,
122 INVALID_MEDIA_PERMISSIONS
123 };
124
125 [[nodiscard]] const char* name() const noexcept override;
126 [[nodiscard]] std::string message(int ev) const override;
127};
128
130 public:
131 enum Value {
132 UNAUTHORIZED = 401,
133 REQUEST_ABORTED = -1,
134 REQUEST_ABORTED_APPLE = 0,
135 JNI_INVALID_ARGUMENT = -101,
136 JNI_OUT_OF_RANGE = -102,
137 EMPTY_RESPONSE = -103,
138 UNKNOWN = -104,
139 };
140
141 [[nodiscard]] const char* name() const noexcept override;
142 [[nodiscard]] std::string message(int ev) const override;
143};
144
153class MILLICAST_API Exception : public std::runtime_error {
154 public:
155 Exception(const Error& err);
157
162 [[nodiscard]] const Error& get_error() const;
163
164 private:
165 Error _err;
166};
167
174template <typename EnumT>
175std::enable_if_t<std::is_error_condition_enum<EnumT>::value, Error>
177 return make_error_condition(value, "");
178}
179
187 const std::string& message);
188
196 const std::string& message);
197
205 const std::string& message);
206
207} // namespace millicast
208
209namespace std {
210template <>
211struct is_error_condition_enum<millicast::AsyncOperationCancelled::Value>
212 : public std::true_type {};
213template <>
214struct is_error_condition_enum<millicast::GenericError::Value>
215 : public std::true_type {};
216} // namespace std
Error category for errors triggered when the operation failed because it was abandoned for various re...
Definition error.h:79
@ TIMEOUT
Operation was cancelled due to a timeout.
Definition error.h:88
@ ABANDONED
Operation was cancelled for unspecified reasons.
Definition error.h:85
const char * name() const noexcept override
The errors reported by the Millicast SDK.
Definition error.h:16
const std::string & message() const
Get the error message.
Definition error.h:54
Error(Error &&) noexcept=default
Error(EnumT value, const std::string &reason)
Definition error.h:39
bool operator==(EnumT val) const
Definition error.h:46
Definition error.h:153
const Error & get_error() const
Get the Error object passed with this exception.
Exception(Error &&err)
Exception(const Error &err)
Error category for other errors.
Definition error.h:98
const char * name() const noexcept override
Value
Definition error.h:100
@ PEERCONNECTION_CREATE_OFFER
Can not create PeerConnection offer.
Definition error.h:112
@ INVALID_JSON
Signaling provided invalid JSON.
Definition error.h:102
@ PEERCONNECTION_NOT_ESTABLISHED
PeerConnection was not established.
Definition error.h:118
@ NO_CREDENTIALS
No credentials are set.
Definition error.h:106
@ WEBSOCKET_HS_FAILED
Websocket not connected.
Definition error.h:110
@ INVALID_OPTIONS
Invalid options set for the request.
Definition error.h:107
@ NULL_LISTENER
Listener not set while it should be.
Definition error.h:121
@ PEERCONNECTION_ADD_TRACKS_FAILED
Can not add tracks.
Definition error.h:117
@ REST_API_ERROR
Director REST API returned an error.
Definition error.h:109
@ INVALID_STATE
Invalid state of the client.
Definition error.h:108
@ TRANSACTION_ERROR
Signaling returned error for the request.
Definition error.h:105
@ PEERCONNECTION_CREATE
Can not create PeerConnection.
Definition error.h:111
Definition error.h:129
const char * name() const noexcept override
Value
Definition error.h:131
#define MILLICAST_TEMPLATE_API
Definition exports.h:46
#define MILLICAST_API
Definition exports.h:51
Definition capabilities.h:15
std::enable_if_t< std::is_error_condition_enum< EnumT >::value, Error > make_error_condition(EnumT value)
Helper to create Error object from the enum value defined in Millicast error category.
Definition error.h:176
Definition error.h:209
Helper for defining error categories in the Millicast SDK.
Definition error.h:67
static const T & instance()
Definition error.h:68