#web-apps #error #thiserror #axum #status-code #proc-macro #response

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

#2153 in Procedural macros

Download history 72/week @ 2024-09-30 46/week @ 2024-10-07 54/week @ 2024-10-14 82/week @ 2024-10-21 51/week @ 2024-10-28 59/week @ 2024-11-04 64/week @ 2024-11-11 112/week @ 2024-11-18 149/week @ 2024-11-25 145/week @ 2024-12-02 108/week @ 2024-12-09 163/week @ 2024-12-16 11/week @ 2024-12-23 88/week @ 2024-12-30 138/week @ 2025-01-06 172/week @ 2025-01-13

409 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
~124K SLoC