Crates.io | axum_thiserror |
lib.rs | axum_thiserror |
version | 0.1.0 |
source | src |
created_at | 2024-01-25 09:02:58.603477 |
updated_at | 2024-01-25 09:02:58.603477 |
description | A Rust procedural macro for custom error handling in web applications, enabling the association of specific HTTP status codes with error types. |
homepage | |
repository | |
max_upload_size | |
id | 1113591 |
size | 8,557 |
axum_thiserror
is a library that offers a procedural macro to allow thiserror
error types to be used as axum
responses.
Add the library to your current project using Cargo:
cargo add axum_thiserror
Then you can create a basic thiserror
error:
#[derive(Error, Debug)]
pub enum UserCreateError {
#[error("User {0} already exists")]
UserAlreadyExists(String),
}
Now you can use axum_thiserror
to implement IntoResponse
on your error:
#[derive(Error, Debug, ErrorStatus)]
pub enum UserCreateError {
#[error("User {0} already exists")]
#[status(StatusCode::CONFLICT)]
UserAlreadyExists(String),
}
This project is licensed under the MIT License.