You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Auto merge of #1929 - jtgeibel:fix-some-error-responses, r=smarnach
Error response refactoring step 2
This is a continuation of #1920. This series captures several changes:
* The controller prelude is split to provide helpers for either cargo or frontend endpoints. Eventually this will be unnecessary, but I see it as a temporary guard rail to encourage the correct usage.
* Several user and session frontend endpoints are updated to return a response with the correct HTTP status. Tests were updated as necessary.
* A `util::errors::http` module is added for concrete error types associated with HTTP status codes. There are more types to be moved here, but for review purposes that can be done in another PR.
* Once `cargo_err` was refactored to use `http::Ok`, all of the description and fallback logic in the `AppError` trait and `ConcreteAppError` type was no longer necessary.
Here is what I have in mind for the next steps in this refactor:
* Add a `not_found` helper that allows a 404 status with an error message for the client. (TBD if this can be merged with the existing `NotFound` type or if that functionality should remain independent.)
* Finish moving types to `http` as applicable.
* Review remaing existing usage of helpers within controllers.
After that groundwork, my final step is to investigate the ability to sanitize error response for cargo at the router level so that `cargo_err` can be removed. It isn't really practical currently to use the correct helper type from within models, since model functionality can be used from either type of endpoint (or both).
The router seems like a strange place for that behavior, but it's where the [error to response conversion](https://github.com/rust-lang/crates.io/blob/4a1542cb17ae50c2bfd0f7e85876d82617e30415/src/router.rs#L139) already happens, and the middleware layer only sees a generic `dyn Error`, not our `AppError`.
With a central place to sanitize errors for old cargo versions, we could even enable it only for old (and empty) user agents.
r? @smarnach
0 commit comments