electionguard-api-python
electionguard-api-python copied to clipboard
Return 400 errors on deserialization failure
Feature Request
Until we have full Pydantic-compliant models (#98), we rely on custom deserialization in the routes, e.g.:
ballots = [PlaintextBallot.from_json_object(ballot) for ballot in request.ballots]
If this deserialization fails, however, it manifests as an opaque 500 error to the client. We should capture deserialization errors and send a 400 with as much information as possible.
Interested please assgn
@gagandeepp you got it!
@rkorsak how to reproduce this error? Also do we need to make changes for all the scenarios in this ticket?
@gagandeepp This error can be replicated by passing any model that doesn't match the request model. Using the example:
ballots = [PlaintextBallot.from_json_object(ballot) for ballot in request.ballots]
will fail if there is an issue with ballot object such as a missing field, a string passed instead of a number, etc.
Yes, it should be addressed at all sections where a model is parsed. Probably a wrapping method.