Kurlyk
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
8namespace kurlyk::utils {
9
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)) {
32 return "Failed to establish WebSocket connection";
34 return "WebSocket connection was closed unexpectedly";
36 return "WebSocket protocol violation detected";
38 return "Unsupported WebSocket data type received";
40 return "Received invalid WebSocket close code";
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
63namespace 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
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.