Kurlyk
Loading...
Searching...
No Matches
ClientErrorCategory.hpp
Go to the documentation of this file.
1#pragma once
2#ifndef KURLYK_HEADER_KURLYK_UTILS_CLIENT_ERROR_CATEGORY_HPP_INCLUDED
3#define KURLYK_HEADER_KURLYK_UTILS_CLIENT_ERROR_CATEGORY_HPP_INCLUDED
4
7
8namespace kurlyk {
9namespace utils {
10
22
25 class ClientErrorCategory : public std::error_category {
26 public:
27 const char* name() const noexcept override {
28 return "http_client";
29 }
30
31 std::string message(int ev) const override {
32 switch (static_cast<ClientError>(ev)) {
34 return "Request was cancelled by the user";
36 return "Request was aborted due to handler destruction";
38 return "Client was not initialized properly";
40 return "Invalid or missing client configuration";
42 return "Operation failed: client is not connected";
44 return "Operation was rejected because the queue limit was exceeded";
46 return "Operation was rejected because the client is shutting down";
47 default:
48 return "Unknown HTTP client error";
49 }
50 }
51 };
52
55 inline const std::error_category& client_error_category() {
56 static ClientErrorCategory instance;
57 return instance;
58 }
59
63 inline std::error_code make_error_code(ClientError e) {
64 return {static_cast<int>(e), client_error_category()};
65 }
66
67} // namespace utils
68} // namespace kurlyk
69
71namespace std {
72 template<>
73 struct is_error_code_enum<kurlyk::utils::ClientError> : true_type {};
74}
75
76#endif // KURLYK_HEADER_KURLYK_UTILS_CLIENT_ERROR_CATEGORY_HPP_INCLUDED
Custom std::error_category for reporting internal client errors not tied to specific protocols (e....
const char * name() const noexcept override
std::string message(int ev) const override
ClientError
Defines errors related to the internal state or lifecycle of the HTTP/WebSocket client.
@ ShuttingDown
Operation was rejected because the owning subsystem is shutting down.
@ NotConnected
Operation requires an active connection but none exists.
@ AbortedDuringDestruction
Request handler was destroyed before completion, causing the request to abort.
@ QueueLimitExceeded
Operation was rejected because the bounded queue is already full.
@ ClientNotInitialized
Operation attempted before client was properly initialized.
@ CancelledByUser
Request was cancelled explicitly by the user via cancel().
@ InvalidConfiguration
Provided configuration is incomplete or invalid.
const std::error_category & client_error_category()
Returns the singleton instance of the ClientErrorCategory.
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.