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