http-error-derive

Crates.iohttp-error-derive
lib.rshttp-error-derive
version0.3.2
sourcesrc
created_at2023-03-08 16:28:31.45646
updated_at2023-10-25 07:46:21.461902
descriptionCreate an enum with error message and http code
homepage
repository
max_upload_size
id804771
size7,584
(JohannesIBK)

documentation

README

Derive for creating easy http api errors

Example

use http_error_derive::HttpError;

#[derive(HttpError)]
enum ApiError {
    #[http(code = 401, message = "You must be logged in to access this resource")]
    Unauthorized,
    #[http(code = 403, message = "You have no permission to access this resource")]
    Forbidden,
}

fn main() {
    println!("{}", ApiError::Forbidden.http_code()); // Some(403u16)
    println!("{:?}", ApiError::Forbidden.http_message()); // Some("You have no permission to access this resource")
}
Commit count: 0

cargo fmt