Stack trace on PUT for collections
dstockto opened this issue · 6 comments
If you PUT to a collection URI something that isn't an array you get a 500 Internal server error and a stack trace. It should probably be a 400 with an error but no stack trace.
Yes, as far as I can remember for the repro steps.
I just tried this running v1.0.7 and was able to get a 500 with a stack trace by sending in a JSON object with a random key/value into a collection PUT URI.
@dstockto I've just tested, and the situation is definitely resolved in the latest versions.
Per @dstockto in IRC, the issue found was specifically when sending an object to PUT for a collection.
I've recreated the issue with the following payload:
{
"foo": "bar"
}
This returns a 500 status, with a problem detail indicating the issue. However, it should return a 400, and likely no stack trace; the issue is the client is sending an invalid data structure.
(The issue is that each item in the object or array should be an object or array, as it's supposed to be a set of entities.)
The issue is in zf-rest, as the checks for array or object are done in the Resource
class:
- https://github.com/zfcampus/zf-rest/blob/93c1f31835519232cad986e35a9ca38eb6f5ef4c/src/Resource.php#L314-L319
- https://github.com/zfcampus/zf-rest/blob/93c1f31835519232cad986e35a9ca38eb6f5ef4c/src/Resource.php#L402-L407
I'll update those exceptions to use a 400 status code.