Skip to content

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

Closed
@bertramakers

Description

@bertramakers

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.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions