Kurlyk
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
8namespace kurlyk {
9namespace utils {
10
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)) {
33 return "Failed to establish WebSocket connection";
35 return "WebSocket connection was closed unexpectedly";
37 return "WebSocket protocol violation detected";
39 return "Unsupported WebSocket data type received";
41 return "Received invalid WebSocket close code";
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
65namespace 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
Error category class for WebSocketError enumeration.
const char * name() const noexcept override
std::string message(int ev) const override
WebSocketError
Represents protocol-level WebSocket errors.
@ CompressionError
Error occurred during compression/decompression.
@ UnsupportedDataType
Received an unsupported data type.
@ ProtocolViolation
Protocol violation occurred during message exchange.
@ ConnectionFailed
WebSocket connection could not be established.
@ UnexpectedClose
Connection was closed unexpectedly (e.g., code 1006).
@ InvalidCloseCode
Server sent an invalid close code.
const std::error_category & websocket_error_category()
Returns the singleton instance of the WebSocket error category.
std::error_code make_error_code(ClientError e)
Creates a std::error_code from a ClientError value.
Primary namespace for the Kurlyk library, encompassing initialization, request management,...
Enables use of ClientError with std::error_code.