Crates.io | http-error-derive |
lib.rs | http-error-derive |
version | 0.3.2 |
source | src |
created_at | 2023-03-08 16:28:31.45646 |
updated_at | 2023-10-25 07:46:21.461902 |
description | Create an enum with error message and http code |
homepage | |
repository | |
max_upload_size | |
id | 804771 |
size | 7,584 |
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")
}