#web-apps #thiserror #axum #status-code #response #applications #error

macro axum_thiserror

A Rust procedural macro for custom error handling in web applications, enabling the association of specific HTTP status codes with error types

1 unstable release

0.1.0 Jan 25, 2024

#2471 in Procedural macros

Download history 159/week @ 2024-11-22 154/week @ 2024-11-29 99/week @ 2024-12-06 144/week @ 2024-12-13 54/week @ 2024-12-20 41/week @ 2024-12-27 156/week @ 2025-01-03 154/week @ 2025-01-10 152/week @ 2025-01-17 78/week @ 2025-01-24 93/week @ 2025-01-31 108/week @ 2025-02-07 275/week @ 2025-02-14 384/week @ 2025-02-21 319/week @ 2025-02-28 323/week @ 2025-03-07

1,315 downloads per month

Custom license

7KB
84 lines

axum_thiserror

axum_thiserror is a library that offers a procedural macro to allow thiserror error types to be used as axum responses.

Usage

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

License

This project is licensed under the MIT License.

Dependencies

~5–12MB
~123K SLoC