Skip to content

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

License

Notifications You must be signed in to change notification settings

Shyrogan/axum_thiserror

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages