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

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

#415 in Procedural macros

Download history 10/week @ 2024-06-24 79/week @ 2024-07-01 59/week @ 2024-07-08 13/week @ 2024-07-15 71/week @ 2024-07-29 81/week @ 2024-08-12 100/week @ 2024-08-19 34/week @ 2024-08-26 145/week @ 2024-09-02 184/week @ 2024-09-09 10/week @ 2024-09-23 16/week @ 2024-09-30 45/week @ 2024-10-07

78 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–1MB
~23K SLoC