2#ifndef _KURLYK_UTILS_HTTP_ERROR_CATEGORY_HPP_INCLUDED
3#define _KURLYK_UTILS_HTTP_ERROR_CATEGORY_HPP_INCLUDED
14 const char*
name() const noexcept
override {
18 std::string
message(
int ev)
const override {
20 case 400:
return "Bad Request";
21 case 401:
return "Unauthorized";
22 case 403:
return "Forbidden";
23 case 404:
return "Not Found";
24 case 408:
return "Request Timeout";
25 case 429:
return "Too Many Requests";
26 case 500:
return "Internal Server Error";
27 case 502:
return "Bad Gateway";
28 case 503:
return "Service Unavailable";
29 case 504:
return "Gateway Timeout";
30 default:
return "HTTP Error " + std::to_string(ev);
40 return std::error_code(status_code, category);
47 return ec.category().name() == std::string(
"http");
Custom error category that maps HTTP status codes (e.g., 404, 500) to human-readable error messages.
std::string message(int ev) const override
const char * name() const noexcept override
bool is_http_error(const std::error_code &ec)
Checks whether the given error code belongs to the HTTP error category.
std::error_code make_http_error(int status_code)
Creates an std::error_code from an HTTP status code.