Closed (works as designed)
Project:
Drupal core
Version:
8.4.x-dev
Component:
serialization.module
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
14 Oct 2016 at 14:04 UTC
Updated:
24 Feb 2017 at 13:58 UTC
Jump to comment: Most recent
Comments
Comment #2
e0ipsoThis is a similar effort that we had to undertake in jsonapi. #2810293: [FEATURE] Use exception event for exception response.
Comment #3
Grayside commentedComment #4
wim leersComment #5
wim leersIt's not clear to me what this is trying to achieve. When/why is this necessary?
But it definitely belongs in the
serialization.modulecomponent (just likeDrupal\serialization\EventSubscriber\DefaultExceptionSubscriberalready is part of that), because the intent is for this to work for any implementation of web services, either "classical REST" (rest.module) or for example JSON API or GraphQL.Comment #6
e0ipsoCore is doing inline exception normalization, which is only alterable by replacing the event subscriber. Instead, it should use the serialization system to deliver the information about the exception in the format it was negotiated.
See how http://cgit.drupalcode.org/drupal/tree/core/lib/Drupal/Core/EventSubscri... normalizes the exception as:
For JSON API (and most probably other formats) we want the ability to control the contents of the response to conform to a specification. We want something close to:
More examples of these inline normalizations are:
Comment #8
wim leersFYI: that specific code you linked to is being deleted in #2825347: 'Accept' header still is used for determining response format of error responses, ?_format= has no effect AND serialization module's exception subscriber does not support status code 500 error responses.
But that doesn't yet address your generic request: let a
Normalizergenerate the error response body forHttpExceptions, instead of lettingKernelEvents::EXCEPTIONsubscribers do that. Which is usually going to be\Drupal\serialization\EventSubscriber\DefaultExceptionSubscriber::on4xx()(since you wrote #6 and those links, we landed #2739617: Make it easier to write on4xx() exception subscribers, which made that a whole lot more consistent.Comment #9
wim leersd.o ate my issue title update :/
Comment #10
wim leersHowever, I do see one flaw in this proposal: #2838949: HttpException Handling Does Not Pass Headers to Responses — results e.g. in missing Allow header for 405 responses added the fix (and test coverage) to ensure that headers associated with an
HttpExceptionobject actually do make it onto the error response too.If the exception is normalized into a response body, then how are we going to get that header to make it onto the error response?
Comment #11
wim leersAnd more importantly, I just discovered at #2829977-29: SerializableHttpException and Drupal\jsonapi\Error\* are not necessary that the only module and format that would benefit from this for now (JSON API) won't actually be able to benefit from this at all:
I do think the idea proposed in this issue is sound, but for now, nothing would be able to benefit from this. Therefore, marking this for now. When the API-first module landscape in D8 is more mature, we should reconsider this!