cdumay_error_http

Crates.iocdumay_error_http
lib.rscdumay_error_http
version0.1.3
created_at2025-04-21 09:35:56.134486+00
updated_at2025-05-23 12:56:16.192994+00
descriptionA Rust Library for JSON error
homepagehttps://github.com/cdumay/cdumay_error_http
repositoryhttps://github.com/cdumay/cdumay_error_http
max_upload_size
id1642474
size20,493
Cédric Dumay (cdumay)

documentation

https://docs.rs/cdumay_error_http

README

cdumay_error_http

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);
Commit count: 8

cargo fmt