Kurlyk
Toggle main menu visibility
Loading...
Searching...
No Matches
WebSocketErrorCategory.hpp
Go to the documentation of this file.
1
#pragma once
2
#ifndef _KURLYK_UTILS_WEBSOCKET_ERROR_CATEGORY_HPP_INCLUDED
3
#define _KURLYK_UTILS_WEBSOCKET_ERROR_CATEGORY_HPP_INCLUDED
4
7
8
namespace
kurlyk::utils
{
9
12
enum class
WebSocketError
{
13
ConnectionFailed
= 1,
14
UnexpectedClose
,
15
ProtocolViolation
,
16
UnsupportedDataType
,
17
InvalidCloseCode
,
18
CompressionError
19
};
20
23
class
WebSocketErrorCategory
:
public
std::error_category {
24
public
:
25
const
char
*
name
() const noexcept
override
{
26
return
"websocket"
;
27
}
28
29
std::string
message
(
int
ev)
const override
{
30
switch
(
static_cast<
WebSocketError
>
(ev)) {
31
case
WebSocketError::ConnectionFailed
:
32
return
"Failed to establish WebSocket connection"
;
33
case
WebSocketError::UnexpectedClose
:
34
return
"WebSocket connection was closed unexpectedly"
;
35
case
WebSocketError::ProtocolViolation
:
36
return
"WebSocket protocol violation detected"
;
37
case
WebSocketError::UnsupportedDataType
:
38
return
"Unsupported WebSocket data type received"
;
39
case
WebSocketError::InvalidCloseCode
:
40
return
"Received invalid WebSocket close code"
;
41
case
WebSocketError::CompressionError
:
42
return
"Compression or decompression error during WebSocket exchange"
;
43
default
:
44
return
"Unknown WebSocket error"
;
45
}
46
}
47
};
48
50
inline
const
std::error_category&
websocket_error_category
() {
51
static
WebSocketErrorCategory
instance;
52
return
instance;
53
}
54
56
inline
std::error_code
make_error_code
(
WebSocketError
e) {
57
return
{
static_cast<
int
>
(e),
websocket_error_category
()};
58
}
59
60
}
// namespace kurlyk::utils
61
63
namespace
std
{
64
template
<>
65
struct
is_error_code_enum<
kurlyk
::utils::WebSocketError> : true_type {};
66
}
67
68
#endif
// _KURLYK_UTILS_WEBSOCKET_ERROR_CATEGORY_HPP_INCLUDED
kurlyk::utils::WebSocketErrorCategory
Error category class for WebSocketError enumeration.
Definition
WebSocketErrorCategory.hpp:23
kurlyk::utils::WebSocketErrorCategory::name
const char * name() const noexcept override
Definition
WebSocketErrorCategory.hpp:25
kurlyk::utils::WebSocketErrorCategory::message
std::string message(int ev) const override
Definition
WebSocketErrorCategory.hpp:29
kurlyk::utils
Definition
Base64Url.hpp:13
kurlyk::utils::WebSocketError
WebSocketError
Represents protocol-level WebSocket errors.
Definition
WebSocketErrorCategory.hpp:12
kurlyk::utils::WebSocketError::CompressionError
@ CompressionError
Error occurred during compression/decompression.
Definition
WebSocketErrorCategory.hpp:18
kurlyk::utils::WebSocketError::UnsupportedDataType
@ UnsupportedDataType
Received an unsupported data type.
Definition
WebSocketErrorCategory.hpp:16
kurlyk::utils::WebSocketError::ProtocolViolation
@ ProtocolViolation
Protocol violation occurred during message exchange.
Definition
WebSocketErrorCategory.hpp:15
kurlyk::utils::WebSocketError::ConnectionFailed
@ ConnectionFailed
WebSocket connection could not be established.
Definition
WebSocketErrorCategory.hpp:13
kurlyk::utils::WebSocketError::UnexpectedClose
@ UnexpectedClose
Connection was closed unexpectedly (e.g., code 1006).
Definition
WebSocketErrorCategory.hpp:14
kurlyk::utils::WebSocketError::InvalidCloseCode
@ InvalidCloseCode
Server sent an invalid close code.
Definition
WebSocketErrorCategory.hpp:17
kurlyk::utils::websocket_error_category
const std::error_category & websocket_error_category()
Returns the singleton instance of the WebSocket error category.
Definition
WebSocketErrorCategory.hpp:50
kurlyk::utils::make_error_code
std::error_code make_error_code(ClientError e)
Creates a std::error_code from a ClientError value.
Definition
ClientErrorCategory.hpp:62
kurlyk
Primary namespace for the Kurlyk library, encompassing initialization, request management,...
std
Enables use of ClientError with std::error_code.
Definition
ClientErrorCategory.hpp:69
include
kurlyk
utils
WebSocketErrorCategory.hpp
Generated by
1.17.0