Skip to content

JsonApiException should support multiple errors at once #22

@chris-doehring

Description

@chris-doehring

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions