#http-error #error-message #error-derive #enums

macro http-error-derive

Create an enum with error message and http code

9 unstable releases (3 breaking)

0.3.2 Oct 25, 2023
0.3.1 Oct 17, 2023
0.2.1 Aug 27, 2023
0.2.0 May 14, 2023
0.0.2 Mar 8, 2023

#344 in Procedural macros

Download history 1/week @ 2024-02-16 5/week @ 2024-02-23 3/week @ 2024-03-01 4/week @ 2024-03-08 3/week @ 2024-03-15 42/week @ 2024-03-29 13/week @ 2024-04-05 3/week @ 2024-04-12

58 downloads per month

MIT license

6KB
91 lines

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")
}

Dependencies

~0.6–1.1MB
~25K SLoC