Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- A handler function, instead of returning a Warp reply/rejection, returns a `Result<Reply, ApiError>.` - This is because rejections are meant to say "this filter can't handle this request, but maybe some other can" (see seanmonstar/warp#388 (comment)). - A rejection means Warp will fall through to another filter and ultimately hit a rejection handler, with people reporting rejections take way too long to process with more routes. - In our case, the error in our handler function is final and we also would like to be able to use the ? operator to bail out of the handler if an error exists, which using a Result type handles for us. - ApiError knows how to convert itself to an HTTP response + status code (error-specific), allowing us to implement Reply for ApiError. - We can't implement `Reply` for `Result<Reply, Reply>` (we didn't make the `Result` type), so we have to add a final function `into_response` that converts our `Result` into a Response. We won't need to do this when seanmonstar/warp#909 is merged: ``` .then(my_handler_func) .map(into_response) ```
- Loading branch information