playframework / playframework/playframework

Improve error handling (HttpErrorHandler)

Open
#6,171 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type:improvement
Dominant language
Scala
Stars
12.6k
Forks
4k
Avg merge
2d 3h
Merged PRs (30d)
29

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the HttpErrorHandler entry point and review the discussions in #6153 and #6116, including the proposed onError method and HttpError object. The issue needs an agreed design covering error types, status codes, headers, and dev versus production handling before implementation can be considered done.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.