Crate cdumay_error_http

Crate cdumay_error_http 

Source
Expand description

License: BSD-3-Clause cdumay_error_http on crates.io cdumay_error_http on docs.rs Source Code Repository

This crate provides structured mapping from HTTP status codes to custom application 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_core ecosystem.
  • 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_error_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)
ExpectationFailed
Error : ExpectationFailed (Kind: ClientError)
FailedDependency
Error : FailedDependency (Kind: ClientError)
Forbidden
Error : Forbidden (Kind: ClientError)
Found
Error : Found (Kind: Redirection)
GatewayTimeout
Error : GatewayTimeout (Kind: ServerError)
Gone
Error : Gone (Kind: ClientError)
HTTPErrorConverter
Converts HTTP status codes into cdumay_core::Error objects.
HttpVersionNotSupported
Error : HttpVersionNotSupported (Kind: ServerError)
ImATeapot
Error : ImATeapot (Kind: ClientError)
InsufficientStorage
Error : InsufficientStorage (Kind: ServerError)
InternalServerError
Error : InternalServerError (Kind: ServerError)
LengthRequired
Error : LengthRequired (Kind: ClientError)
Locked
Error : Locked (Kind: ClientError)
LoopDetected
Error : LoopDetected (Kind: ServerError)
MethodNotAllowed
Error : MethodNotAllowed (Kind: ClientError)
MisdirectedRequest
Error : MisdirectedRequest (Kind: ClientError)
MovedPermanently
Error : MovedPermanently (Kind: Redirection)
MultipleChoices
Error : MultipleChoices (Kind: Redirection)
NetworkAuthenticationRequired
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)
PayloadTooLarge
Error : PayloadTooLarge (Kind: ClientError)
PaymentRequired
Error : PaymentRequired (Kind: ClientError)
PermanentRedirect
Error : PermanentRedirect (Kind: Redirection)
PreconditionFailed
Error : PreconditionFailed (Kind: ClientError)
PreconditionRequired
Error : PreconditionRequired (Kind: ClientError)
ProxyAuthenticationRequired
Error : ProxyAuthenticationRequired (Kind: ClientError)
RangeNotSatisfiable
Error : RangeNotSatisfiable (Kind: ClientError)
RequestHeaderFieldsTooLarge
Error : RequestHeaderFieldsTooLarge (Kind: ClientError)
RequestTimeout
Error : RequestTimeout (Kind: ClientError)
SeeOther
Error : SeeOther (Kind: Redirection)
ServiceUnavailable
Error : ServiceUnavailable (Kind: ServerError)
TemporaryRedirect
Error : TemporaryRedirect (Kind: Redirection)
TooManyRequests
Error : TooManyRequests (Kind: ClientError)
Unauthorized
Error : Unauthorized (Kind: ClientError)
UnavailableForLegalReasons
Error : UnavailableForLegalReasons (Kind: ClientError)
UnprocessableEntity
Error : UnprocessableEntity (Kind: ClientError)
UnsupportedMediaType
Error : UnsupportedMediaType (Kind: ClientError)
UpgradeRequired
Error : UpgradeRequired (Kind: ClientError)
UriTooLong
Error : UriTooLong (Kind: ClientError)
UseProxy
Error : UseProxy (Kind: Redirection)
VariantAlsoNegotiates
Error : VariantAlsoNegotiates (Kind: ServerError)

Constants§

ClientError
ErrorKind : ClientError (400) - Client Error
Redirection
ErrorKind : Redirection (300) - Redirect
ServerError
ErrorKind : ServerError (500) - Server Error