Skip to content
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

No body content for StatusCode::InternalServerError #614

Closed
nwilcox93 opened this issue Jun 24, 2020 · 2 comments
Closed

No body content for StatusCode::InternalServerError #614

nwilcox93 opened this issue Jun 24, 2020 · 2 comments

Comments

@nwilcox93
Copy link

if !res.status().is_server_error() {

When returning an Err(http_types::Error) inside a handler that returns a tide::Result, the message for the error is not displayed in the browser if the status is StatusCode::InternalServerError. I can work around this by returning Ok(Response) with StatusCode::InternalServerError. It seems like it is an anti-pattern to return Ok(Response) when an error occurred on the server. Just looking for some clarification the correct approach.

Thanks!

@jbr
Copy link
Member

jbr commented Jun 24, 2020

See #570 for some changes related to this. In short, error handling is likely changing substantially in the near future

@jbr
Copy link
Member

jbr commented Jul 27, 2020

The solution for this in tide >= 0.12 is to add a middleware that catches responses with an attached error and builds a string body with it, something like:

    app.middleware(After(|mut res: Response| async {
        if let Some(err) = res.take_error() {
            res.set_body(err.to_string()) // or json, or html, etc, whatever is appropriate for your app
        }
        Ok(res)
    }));

@jbr jbr closed this as completed Jul 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants