Description
Right now, I see occasional 500 errors in our logs that look like this (some info elided):
Nov 25 07:18:41 crates-io app/web.1 at=error method=GET path="/api/v1/crates?page=1&per_page=100%22%EF%BC%8Cexception" service=1ms status=500 error="invalid digit found in string"
I have a suspicion that somehow we're generating links that contain (decoded) ",exception
, but I haven't figured out how yet.
Whether we're causing these incorrectly formed URLs or not, the backend should be responding with 400 Bad Request, not 500 because of an invalid digit in the string.
Implementation instructions
I've created a branch with a commit that adds some failing tests; please include those tests and get them to pass as part of your PR :) (editing the tests might be necessary, and bonus points if you add tests in the pagination controller helper for the happy paths and other error cases!)
The problem is in the pagination controller helper:
To return 400 instead of 500, you'll need to add some map_err
calls to return BadRequest
errors. Here's an example of someplace we do this; search for bad_request
to see other examples.
Let me know if you have any questions or if any of the instructions don't make sense!