Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsonApiException should support multiple errors at once #22

Open
chris-doehring opened this issue Mar 23, 2020 · 1 comment
Open

JsonApiException should support multiple errors at once #22

chris-doehring opened this issue Mar 23, 2020 · 1 comment

Comments

@chris-doehring
Copy link

Hi there!

first of all: Thank you for creating such a protocol close php implementation of the JSON API! Nicely done!

I'm currently using your server project and therefor the common library to implement a custom Exception handling and I came across a missing protocol feature: Multiple error objects.

According to the protocol, the error document will return a collection of errors, which you correctly implemented, but your JsonApiException by default only supports one error: A representation of the current Throwable. I understand that implementing an error collection on php Exception level is a bit complicated, since you basically only have error details of the current Throwable.

I'm currently solving that issue by creating my own JsonApiException class which only represents an error collection and http status code with unrelated Throwable message or code. Normally, you don't need such an error collection when working with php. You have one exception which you translate and that's it. But a practical example where this would be beneficial is input validation. Let's assume we are calling the resource creation action with multiple attributes and some of them fail in the validation: Here it would make sense to return all errors of those input fields at once, but that's not possible currently by default.

I'm currently only implementing that feature in my private project. If I have some free time soon, I might implement it in a fork of your project or maybe someone else might be interested in implementing this.

@chris-doehring
Copy link
Author

I had the time to work on this and I must say it worked out nicely :)
All changes are included in my pull request #25

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant