Problem/Motivation

Existing error messages in Drupal REST responses are one dimensional—a string contextualized by an HTTP status code. This is limiting in several ways:

  • It is very difficult to provide adequate depth of insight into an error via a one-line message.
  • Categorization of "sub-types" below the level of status code and above the specific error message is difficult, inhibiting ease of troubleshooting research
  • The response is too basic to facilitate more advanced integration around fault tolerance and error handling UX.

Proposed resolution

RFC 7807: Problem Details provides a description for structured XML or JSON responses that facilitate greater detail in the error messages.

A few thoughts on some of the available properties:

  • type can link to documentation pages on Drupal.org about the error category, driving developers to a landing page to help facilitate research.
  • title can be made high-level and unique by type, to facilitate googling without the kinds of identifiers, URIs, and file paths that are unique to an environment.

  • instance might be used in the future for more targeted knowledge base building. With some coordination, dedicated URLs or sections within the type URL could be linked to for more specific delving.

Example

{
  "type": "<url>",
  "title": "Access denied to content",
  "status": 403,
  "details": "Currently authenticated user lacks permission to view content on this site."
  "instance": "<url>#access-denied-to-content",
}

Furthermore, problem-specific extensions allow additional properties to be added. There are many future enhancements that might be considered from there.

Remaining tasks

  1. Decide from a product standpoint if this is a good direction for the Drupal REST implementation
  2. Create a facility to support message output in the application/problem+json or application/problem+xml format.
  3. Perform an initial survey of REST error messages to determine categories.
  4. For each error category, find or prepare a documentation page to server as the type URL.
  5. Convert errors thrown in the course of REST responses to be handled by the new error response mechanism.

Out-of-initial-scope

  • Handling multiple problems per error response
  • Coordinating documentation for error "instance" property
  • Adding flags to tailor the error response based on maintenance mode or other site states

User interface changes

REST error responses will change in structure and Content Type. Code which parses and uses the existing structure will break, though backwards compatibility might be preserved by using existing properties as "extensions" per the RFC.

API changes

New representation for errors will likely result in API additions. Changes in error handling might result in API changes to add additional parameters to some exceptions.

Data model changes

None.

Comments

Grayside created an issue. See original summary.

dawehner’s picture

I really like the idea to use an RFC for our error messages. It makes things much more relieable/sane in the first place.

Wim Leers’s picture

Thanks, I love this proposal! You've probably noticed I've done lots of fixes in this area already, see the "DX" sections of both #2721489: REST: top priorities for Drupal 8.2.x and #2794263: REST: top priorities for Drupal 8.3.x. But I completely agree that following an RFC to standardize/structure REST error responses has the potential to help a lot.

How does this relate to #1916302: RFC 7807: "Problem Details for HTTP APIs" — serve REST error responses as application/problem+json?

Grayside’s picture

Somehow missed that issue, effectively it's a blocker on this, which advocates for one of the two proposed formats.

Grayside’s picture

The improvements to the error messages is part of what inspired this issue—I think there's enough clarity in place now and momentum to keep going that it's a good time to start planning how to reach the next level.

e0ipso’s picture

If possible I'd like to have core be flexible enough to override the HttpException normalizer. Some specifications, like JSON API will have opinionated formats for errors as well.

This RFC will be considered a good fallback if the negotiated format does not specify anything different.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Wim Leers’s picture

Category: Plan » Feature request
Wim Leers’s picture

Status: Postponed » Closed (duplicate)