Repository navigation
Add error code for JsonApi errors. - #2922
Conversation
|
The target branch is good, as it's a new feature! |
|
I made the requested changes rebased and squashed hope it's fine now. It looks like behat tests are failing allthough I only rebased the code onto master @dunglas |
|
any update on this? |
|
There are some concerns on whether this is a good idea or not (exposing exception codes). |
|
The JSON:API spec says it should be an "application-specific error code". We cannot assume that all exceptions thrown are controlled by / originate from the application. I don't think it's a good idea to map the exception code to error code indiscriminately. I'm -1 unless we introduce a mapping or some other way of doing that conversion. |
|
Currently the exception code is only set of its not the default code which is 0. the idea of an exception code to error code mapping sounds interesting so if you want I can add that if you point me to the right config place where I should put it. Another idea would be to add an Interface that can be used to throw exception that have an application error code. I'm not sure about the naming but something like: // using anonymous classes
throw new class('my exception', 12345) extends \Exception implements ApplicationErrorInterface |
I think that's a dangerous assumption. The exception code could be set by another library, not the app. So we may be exposing some exception code that makes no sense to the client. But the main problem is that the error code could be a string. There is no reason to just take the exception code. So yeah, let's introduce a mapping (probably too cumbersome to use...) or an interface like this: interface ErrorCodeExceptionInterface extends \Throwable
{
public static function getErrorCode(): string;
}(Static method because the error code should not change between different instances of the class.) |
|
Hi, |
72d964d to
51e9141
Compare
|
just a bump to see if something if missing or can this be merged? |
|
Closing as I've explained why this is not the right approach. |
|
Sorry, I see you've updated to a different approach. |
b4afd89 to
beb5e5b
Compare
|
Only minor changes. LGTM! 👍 |
|
I have applied your suggestions thanks for the help :) |
… error codes during normalization of errors. api-platform#2922
Co-Authored-By: Teoh Han Hui <teohhanhui@gmail.com>
|
@teohhanhui I fixed errors caused by my PR I think the other problems are not related to my changes. |
|
Thanks @gries! 🎉 |
Hi,
I added the possibility to specify an error code for JsonApi Errors as specified in the JsonApi Spec.
https://jsonapi.org/format/#errors
In short when throwing an Exception like:
the Normalizer now uses the Exception Code like so:
It's a minor change so I'm not sure if master is the correct base branch.