Skip to content

Bug: Exception::__construct(): Argument #2 ($code) must be of type int, array given #85

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

Closed
bertramakers opened this issue Sep 28, 2023 · 1 comment
Assignees
Labels
bug Something isn't working
Milestone

Comments

@bertramakers
Copy link
Contributor

When we (accidentally) try to update a resource with a different id in the URL as in the body, we get the following PHP error:

Exception::__construct(): Argument #2 ($code) must be of type int, array given

Thrown here: https://github.com/tobyzerner/json-api-server/blob/main/src/Endpoint/Concerns/SavesData.php#L43-L45

This line was changed in June I see: 3bdac86#diff-4e1c4cc32773a07b137197237630335d71c60511db9adc163b51a8c4c54f0443L43-R45

The issue seems to be that neither ConflictException nor its parent classes have a constructor to actually do something with the "source" array, and the native constructor of Exception gets called which expects an integer as second argument (for the exception code).

It does not occur for BadRequestException because that one does have a custom constructor: 3bdac86#diff-90e3070308e4f4b6b74f5bde2dc516df0f5eed0426e2777eea15f9bd867f7591

I wouldn't mind fixing this in a PR but I'm unsure how you'd want to proceed this. Either ConflictException should also support the "source" argument (but I'm not sure what impact that would have on the rest of the library) or no source should be included when throwing it.

@tobyzerner
Copy link
Owner

Thanks for the detailed report. I think I want to fix this as part of some broader improvements to error handling (i.e. every type of exception should have the ability to have a source, not just Bad Request)

@tobyzerner tobyzerner added the bug Something isn't working label Nov 7, 2023
@tobyzerner tobyzerner self-assigned this Nov 7, 2023
@tobyzerner tobyzerner added this to the v1.0 milestone Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants