Crate actix_web_error

source ·
Expand description

Error responses for actix-web made easy.

This crate will make it easy implementing actix_web::ResponseError for errors. It’s best used in combination with thiserror.

Error Responses

  • Json will respond with JSON in the form of { "error": <Display representation> } (application/json).
  • Text will respond with the Display representation of the error (text/plain).


#[derive(Debug, thiserror::Error, actix_web_error::Json)]
#[status(BAD_REQUEST)] // default status for all variants
enum MyError {
    #[error("Missing: {0}")]
    MissingField(&'static str),
    #[error("Malformed Date")]
    #[error("Internal Server Error")]
    #[status(500)] // specific override

#[derive(Debug, thiserror::Error, actix_web_error::Text)]
#[error("Item not found")]
struct MyOtherError;

Derive Macros