carllerche / tower-web

A fast, boilerplate free, web framework for Rust
MIT License
981 stars 51 forks source link

Server errors in Extract #173

Closed lnicola closed 5 years ago

lnicola commented 5 years ago

I don't think there's a way to report server errors that occur during extraction. There is a tower_web::extract::Error::web function, but it's private.

This would be useful when doing e.g. IO (maybe looking up a session in a database), which can fail due to reasons outside of the client's control.

manifest commented 5 years ago

The web function is already public in the master branch, and with this PR merged, we won't need web function because From<error::error::Error> implementation for extract:error::Error looks as a better alternative.

manifest commented 5 years ago

There is summary on changes the PR introduces.

lnicola commented 5 years ago

Thanks, that seems nice. One question: should internal_error be public, too? It can be emulated with the same code (Error::web(ErrorKind::internal().into())), but might come in handy.

EDIT: well, I guess that #171 will deprecate that pattern.

manifest commented 5 years ago

@lnicola the PR will make the following possible

Error::from(StatusCode::INTERNAL_SERVER_ERROR).into()