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

Invalid page size parameter causes a 500 Internal Server Error #10

Open
weierophinney opened this issue Dec 31, 2019 · 1 comment
Open

Comments

@weierophinney
Copy link
Contributor

If you configure a page size parameter, values that are not positive integers (or -1) will result in a 500 Internal Server Error and a stack trace. The exceptions that trigger this (vendor/zfcampus/zf-hal/src/Collection.php line 302 and 310) indicate the problem is one of validation rather than something going wonky on the server. IMHO, this should not be a 500, but could either be a 400 or 422 or it could "fail safe" back to using the configured default and not causing an error at all.


Originally posted by @dstockto at zfcampus/zf-hal#141

@weierophinney
Copy link
Contributor Author

Since this was opened, the class has been updated so that -1 indicates no pagination. So the above is still true for values that are not positive integers, other than -1. The exceptions thrown are now on 287 and 295 instead of the original 302 and 310.

It appears the fix for this would probably be in zf-rest in \ZF\Rest\RestController in prepareHalCollection. The call to $collection->setPageSize($this->getPageSize()); could be wrapped in a try..catch and return an ApiProblem rather than letting the ZF\Hal\Exception\InvalidArgumentException bubble all the way out and become a 500. If this sounds like an acceptable way of handling it, I'm happy to make a PR. I don't think this should be a 5xx error though.


Originally posted by @dstockto at zfcampus/zf-hal#141 (comment)

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