actix_error_proc
actix_error_proc
is a small library to integrate thiserror
into actix_web
routes
with procedural macros.
This library has two main macros as well as a thiserror
re export under the thiserror
feature.
ActixError
This macro is used together with thiserror::Error
and it allows the user
to add a few more attributes to the error enumerable.
A basic usage of this macro looks like this
use ; // Error is a thiserror re export.
By default the response is simply the status code and the #[error("...")]
format
as a body. But you can change that with the transformer
.
There is another attribute you can add called actix_error
at the enumerable level
that lets you change how the response will look, for now it only has the transformer
variable, but in a future it might have more things.
An example usage of the transformer
variable looks like this
use ; // Error is a thiserror re export.
// This should not throw any error, the errors should be handled
// at the request level.
// reference `transform_error` here.
All of this is to be used with the proof_route
attribute.
proof_route
This attribute wraps an actix_web
route changing it's result into a Result<HttpResponse, E: Into<HttpResponse>>
where E is your custom enumerable that implements Into<HttpResponse>
because of the ActixError
derive macro.
There is a type alias for that Result which is actix_error_proc::HttpResult<E>
.
An example usage of the proof_route
procedural macro look like this
use ; // Error is a thiserror re export.
use crate User;
use
use ;
use Error as IoError;
// assuming we have a wrapped enum
async
async
Contributing
Before making a blind pull request please, open an issue we can talk about it and then if it's necessary you can make a pull request, I actively maintain this project so I'll read all the issues when possible.
You can also email me at esteve@memw.es
. Thanks.