Kurlyk
Loading...
Searching...
No Matches
ClientErrorCategory.hpp
Go to the documentation of this file.
1#pragma once
2#ifndef _KURLYK_UTILS_CLIENT_ERROR_CATEGORY_HPP_INCLUDED
3#define _KURLYK_UTILS_CLIENT_ERROR_CATEGORY_HPP_INCLUDED
4
7
8namespace kurlyk::utils {
9
19
22 class ClientErrorCategory : public std::error_category {
23 public:
24 const char* name() const noexcept override {
25 return "http_client";
26 }
27
28 std::string message(int ev) const override {
29 switch (static_cast<ClientError>(ev)) {
31 return "Request was cancelled by the user";
33 return "Request was aborted due to handler destruction";
35 return "Client was not initialized properly";
37 return "Invalid or missing client configuration";
39 return "Operation failed: client is not connected";
40 default:
41 return "Unknown HTTP client error";
42 }
43 }
44 };
45
48 inline const std::error_category& client_error_category() {
49 static ClientErrorCategory instance;
50 return instance;
51 }
52
56 inline std::error_code make_error_code(ClientError e) {
57 return {static_cast<int>(e), client_error_category()};
58 }
59
60} // namespace kurlyk::utils
61
63namespace std {
64 template<>
65 struct is_error_code_enum<kurlyk::utils::ClientError> : true_type {};
66}
67
68#endif // _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.
@ NotConnected
Operation requires an active connection but none exists.
@ AbortedDuringDestruction
Request handler was destroyed before completion, causing the request to abort.
@ 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.