Use values from ProblemExceptionInterface#7776
Conversation
|
Mhhh interesting, Symfony uses The use looks quite correct I like the patch. Note to self: core/src/State/ApiResource/Error.php Lines 198 to 203 in e0ba006 It may also need fixing. If you could add a test to JsonProblemTest it'd be great (informations on how to run tests are inside CONTRIBUTING.md) |
|
Do you want me to update Would you consider this a feature or bug fix? Knowing that, I can potentially rebase, and also fix the first commit message to satisfy commitlint. |
Indeed this would be nice. We can leave that on the |
0d0a740 to
9e5e095
Compare
9e5e095 to
2a6bd07
Compare
|
thanks! |
I have a couple of custom exceptions defined that all implement the ProblemExceptionInterface (as described in the documentation). However, in the response they're still rendered as follows. I want the values to be shown that I have defined in the methods required by the interface.
{ "type": "/errors/500", "title": "An error occurred", "status": 500, "detail": "Exception message be here" }I dove into the ErrorHandler that's defined for Laravel, and noticed that it always calls
Error::createFromException($exception, $statusCode). It's this method that sets those values. In this PR, I added a condition that if the exception passed to it is an instance of ProblemExceptionInterface, then the Error will be created entirely using the values from that interface.Following this change, the following exception generates the following output:
{ "type": "teapot", "title": "I am a teapot", "status": 418, "detail": "No coffee" }I'm not sure if you see this as a feature or a (breaking) bug fix, so feel free to correct me if necessary and I'll happily rebase it to the correct 4.x branch. Or perhaps there's another way to achieve this that I'm not seeing at the moment.