Problem/Motivation
We validate the entities we submit, but well, we don't make this information easily parsable, as its a long blob of a string, and APIs can properly use it.
Proposed resolution
Make the information easily accessible by leveraging the normalizer framework.
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #39 | interdiff-2856110-37-39.txt | 2.42 KB | br0ken |
| #39 | 2856110-39.patch | 16.7 KB | br0ken |
Comments
Comment #2
dawehnerComment #3
wim leersAdding related issues.
Comment #4
wim leersWhat a great start! Thanks, @dawehner!
I'm pretty sure this belongs in the
serializationmodule.Comment #5
dawehnerFair point. I struggled a bit with the decision, but then I went with rest module, not really for any particular reason.
One question is: How do we deal with the potential BC break?
Comment #6
wim leersI doubt any of the existing clients are parsing the current error response bodies. Which is exactly why you're doing this. Not even https://github.com/acquia/waterwheel.js is doing this.
So… yes this is a BC break technically. But it's also just to make something even remotely usable. The current responses are not usable.
Therefore I think the same BC strategy as we used in #2751325: All serialized values are strings, should be integers/booleans when appropriate seems appropriate.
Comment #7
dawehnerSome progress:
* Register the normalizer
* Move to the serialization module
* Encode the actual errors
Comment #9
dawehnerThis should fix a good bunch of failures.
Comment #11
dawehnerFixing a couple of more issues.
Comment #13
dawehnerMore fixed ...
Comment #15
br0kenLet's see whether this helps to get rid of couple errors.
Comment #17
br0kenComment #18
br0kenComment #19
br0kenGosh...
Comment #22
dawehnerSome test fixes ...
Comment #24
br0kenComment #26
dawehner@BR0kEN
Can you explain your recent change? I think we cannot just drop the instanceof checking?
Comment #27
br0ken@dawehner, I was wrongly thought that
supportsNormalizationmethod called somewhere. But now I'm seeing it's not.By the way, how are you running this locally? In case when I don't want to run whole
restgroup. Single test (e.g.core/modules/rest/tests/src/Functional/EntityResource/Node/NodeJsonAnonTest.php) fails every time with something like:Comment #28
br0kenComment #30
br0kenHm, but nevertheless we shouldn't call
supportsNormalization()since this happens in\Symfony\Component\Serializer\Serializer::getNormalizer().Comment #31
br0kenComment #33
br0kenComment #35
br0kenComment #37
br0kenComment #39
br0kenOkay, this will solve couple errors.
Comment #41
damiankloip commentedA few comments:
I don't think we can do this at all, when we support \Exception, so this normalizer would catch anything. I am also not 100% convinced about having a normalizer for this exception handling. This should only support EntityValidationExceptions I think, in any case. Which means possibly an exception normalizer for regular exceptions too. That wouild also require things to be handled a bit differently in \Drupal\serialization\EventSubscriber\DefaultExceptionSubscriber::on4xx.
Does having the single code in checkSupport() behave the same as the instanceof check we have now? I'm not sure..
Maybe this parameter should be named $type and have the casting from object still?
Refactoring this piece of the logic seems possibly out of scope here?
Why is this change needed for this test?
Comment #42
br0ken@damiankloip
Now, instead of an array, serializes exception object.
instanceofis not good approach, because for instance\RuntimeExceptionis not an instance of\Exception. That's why these changes were made.supportsNormalizationmethodComment #43
br0ken@damiankloip, visual answer on your 5 question available here: https://www.drupal.org/pift-ci-job/630951. The
Serialization.Serializationsection.Comment #44
dawehnerAdding the related issue: #2863778: Clean up \Drupal\hal\Normalizer\NormalizerBase: duplicate less from the parent class \Drupal\serialization\Normalizer\NormalizerBase
Comment #45
dawehnerComment #46
wim leersQuoting #1916302-16: RFC 7807: "Problem Details for HTTP APIs" — serve REST error responses as application/problem+json:
Please share your thoughts here or on that issue. I think this issue still makes a ton of sense, but I think it'd be good to adopt RFC 7807 for this, instead of inventing our own approach.
Comment #59
smustgrave commentedSeems postponed issue has since been closed.