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.
- 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.
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.
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
- Decide from a product standpoint if this is a good direction for the Drupal REST implementation
- Create a facility to support message output in the
application/problem+json
orapplication/problem+xml
format. - Perform an initial survey of REST error messages to determine categories.
- For each error category, find or prepare a documentation page to server as the type URL.
- 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
Comment #2
dawehnerI really like the idea to use an RFC for our error messages. It makes things much more relieable/sane in the first place.
Comment #3
Wim LeersThanks, 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?
Comment #4
Grayside CreditAttribution: Grayside at Phase2 for Norwegian Cruise Line commentedSomehow missed that issue, effectively it's a blocker on this, which advocates for one of the two proposed formats.
Comment #5
Grayside CreditAttribution: Grayside at Phase2 for Norwegian Cruise Line commentedThe 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.
Comment #6
e0ipsoIf 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.
Comment #8
Wim LeersComment #9
Wim LeersI'm actually positive now that this is a 100% duplicate of #1916302: RFC 7807: "Problem Details for HTTP APIs" — serve REST error responses as application/problem+json.
So, moved this issue summary to that issue, and marking this a duplicate.
See #1916302-19: RFC 7807: "Problem Details for HTTP APIs" — serve REST error responses as application/problem+json.