Expand description
This crate provides structured mapping from HTTP status codes to custom application including error types using the cdumay_core crate. It is especially useful when you want to handle HTTP error responses in a standardized and extensible way.
§Features
- Maps common HTTP status codes (300–511) to well-defined application-specific errors.
- Integrates seamlessly with the
cdumay_coreecosystem. - Allows contextual error data and custom messages.
- Supports conversion from
u16
§Usage
§Define Error Kinds and Errors
The define_kinds! macro associates each HTTP status code with:
- A numerical HTTP status code
- A descriptive error label
The define_errors! macro maps those kinds into named error types (e.g., NotFound, TooManyRequests, etc.).
use std::collections::BTreeMap;
use serde_value::Value;
use cdumay_http::HTTPErrorConverter;
let mut context = BTreeMap::new();
context.insert("url".to_string(), Value::String("https://example.com".to_string()));
let error = HTTPErrorConverter::from_u16(404, context);
println!("{:?}", error);Structs§
- BadGateway
- Error : BadGateway (Kind:
ServerError) - BadRequest
- Error : BadRequest (Kind:
ClientError) - Conflict
- Error : Conflict (Kind:
ClientError) - Expectation
Failed - Error : ExpectationFailed (Kind:
ClientError) - Failed
Dependency - Error : FailedDependency (Kind:
ClientError) - Forbidden
- Error : Forbidden (Kind:
ClientError) - Found
- Error : Found (Kind:
Redirection) - Gateway
Timeout - Error : GatewayTimeout (Kind:
ServerError) - Gone
- Error : Gone (Kind:
ClientError) - HTTP
Error Converter - Converts HTTP status codes into
cdumay_core::Errorobjects. - Http
Version NotSupported - Error : HttpVersionNotSupported (Kind:
ServerError) - ImATeapot
- Error : ImATeapot (Kind:
ClientError) - Insufficient
Storage - Error : InsufficientStorage (Kind:
ServerError) - Internal
Server Error - Error : InternalServerError (Kind:
ServerError) - Length
Required - Error : LengthRequired (Kind:
ClientError) - Locked
- Error : Locked (Kind:
ClientError) - Loop
Detected - Error : LoopDetected (Kind:
ServerError) - Method
NotAllowed - Error : MethodNotAllowed (Kind:
ClientError) - Misdirected
Request - Error : MisdirectedRequest (Kind:
ClientError) - Moved
Permanently - Error : MovedPermanently (Kind:
Redirection) - Multiple
Choices - Error : MultipleChoices (Kind:
Redirection) - Network
Authentication Required - Error : NetworkAuthenticationRequired (Kind:
ServerError) - NotAcceptable
- Error : NotAcceptable (Kind:
ClientError) - NotExtended
- Error : NotExtended (Kind:
ServerError) - NotFound
- Error : NotFound (Kind:
ClientError) - NotImplemented
- Error : NotImplemented (Kind:
ServerError) - NotModified
- Error : NotModified (Kind:
Redirection) - Payload
TooLarge - Error : PayloadTooLarge (Kind:
ClientError) - Payment
Required - Error : PaymentRequired (Kind:
ClientError) - Permanent
Redirect - Error : PermanentRedirect (Kind:
Redirection) - Precondition
Failed - Error : PreconditionFailed (Kind:
ClientError) - Precondition
Required - Error : PreconditionRequired (Kind:
ClientError) - Proxy
Authentication Required - Error : ProxyAuthenticationRequired (Kind:
ClientError) - Range
NotSatisfiable - Error : RangeNotSatisfiable (Kind:
ClientError) - Request
Header Fields TooLarge - Error : RequestHeaderFieldsTooLarge (Kind:
ClientError) - Request
Timeout - Error : RequestTimeout (Kind:
ClientError) - SeeOther
- Error : SeeOther (Kind:
Redirection) - Service
Unavailable - Error : ServiceUnavailable (Kind:
ServerError) - Temporary
Redirect - Error : TemporaryRedirect (Kind:
Redirection) - TooMany
Requests - Error : TooManyRequests (Kind:
ClientError) - Unauthorized
- Error : Unauthorized (Kind:
ClientError) - Unavailable
ForLegal Reasons - Error : UnavailableForLegalReasons (Kind:
ClientError) - Unprocessable
Entity - Error : UnprocessableEntity (Kind:
ClientError) - Unsupported
Media Type - Error : UnsupportedMediaType (Kind:
ClientError) - Upgrade
Required - Error : UpgradeRequired (Kind:
ClientError) - UriToo
Long - Error : UriTooLong (Kind:
ClientError) - UseProxy
- Error : UseProxy (Kind:
Redirection) - Variant
Also Negotiates - Error : VariantAlsoNegotiates (Kind:
ServerError)
Constants§
- Client
Error - ErrorKind : ClientError (400) - Client Error
- Redirection
- ErrorKind : Redirection (300) - Redirect
- Server
Error - ErrorKind : ServerError (500) - Server Error