Skip to content

Improve error handling (HttpErrorHandler) #6171

@richdougherty

Description

@richdougherty

There has been a bit of discussion about error handling in Play, both online (#6153, #6116) and offline. I'm creating this issue to capture some of these discussions in one place.

From #6153:

  • When to include a Result object in the error information?
  • How to tell "where" an error happens? Did it happen in application code or in Play code? (My comment: could the stack trace could be used for this?)
  • Do we need more types of errors/exceptions? We should probably try and avoid throwing plain RuntimeExceptions, at least.
  • Do we need more types of errors/exceptions so it's easier for applications to differentiate between types of exceptions.
  • We need a way to provide a status code for server errors (5xx) instead of always defaulting to 500 errors.
  • Also need to think about headers, e.g. a 505 usually needs a Connection: close header, a 503 status can be paired with a Retry-After header, a 401 status should include a WWW-Authenticate header.

From #6116:

  • Overriding specific error codes (e.g. 404) but not others.
  • Dev vs prod mode handling.

Suggestion from @gmethvin:

  • Replace the various onXxxError methods with an onError method that takes some sort of HttpError object as an argument. This allows us to evolve the API more easily because we can add fields to the HttpError object over time instead of needing to add new parameters to methods in the HttpErrorHandler interface.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions