Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

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

Open
dstockto opened this issue May 11, 2016 · 2 comments
Open

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

dstockto opened this issue May 11, 2016 · 2 comments

Comments

@dstockto
Copy link

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.

@dstockto
Copy link
Author

dstockto commented Sep 5, 2016

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.

@weierophinney
Copy link
Member

This repository has been closed and moved to laminas-api-tools/api-tools-hal; a new issue has been opened at laminas-api-tools/api-tools-hal#10.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants