-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integrating with actix-web #72
Comments
Thank you and I'm glad. Hearing that puts a smile on my face ^_^
The standard approach is to use a feature flag to implement the given trait in one crate or the other. It looks like someone already requested1 support for anyhow in actix-web and got denied, so having the trait implementation live in actix-web is likely out of the question, tho I suppose it would be worth double checking if the maintainer involved in that decision is still the lead maintainer or not. Edit: it seems that they are not infact involved anymore Looking at In the end it looks like this is a rather large mess. I can understand why actix decided to define their own Footnotes |
It actually looks like the maintainer who closed that PR isn't the one maintaining actix-web anymore, so I think it's almost certainly worth pinging @robjtede here to get their opinion and to see if we could start working on migrating |
For those looking for a solution to use in the meantime, this pattern combining #[derive(thiserror::Error, Debug)]
pub enum RouteNameHereError {
#[error("{0}")]
ValidationError(String),
#[error(transparent)]
UnexpectedError(#[from] eyre::Error),
}
impl ResponseError for RouteNameHereError {
fn status_code(&self) -> StatusCode {
match self {
RouteNameHereError::ValidationError(_) => StatusCode::BAD_REQUEST,
RouteNameHereError::UnexpectedError(_) => StatusCode::INTERNAL_SERVER_ERROR,
}
}
}
#[get("/route-name-here")]
async fn route_name_here() -> Result<(), RouteNameHereError> {
Err(eyre!("Something went wrong!"))
} Source: https://www.lpalmieri.com/posts/error-handling-rust/#using-anyhow-as-opaque-error-type |
Hi, great library, I'm enjoying it. I would like to somehow support the
?
operator in my actix-web app. The actix-web HTTP handler's support aResult<_,_>
return value so that means?
will work, but the Err variant needs to implement their ResponseError trait: https://github.com/actix/actix-web/blob/master/actix-web/src/error/response_error.rs .I can't implement ResponseError for eyre::Result because of the orphan rule. Any tips on how I could use eyre::Result in this scenario? And food for thought, here is how I hacked some existing code to use the stdlib Result in actix-web:
The text was updated successfully, but these errors were encountered: