electionguard-api-python icon indicating copy to clipboard operation
electionguard-api-python copied to clipboard

Return 400 errors on deserialization failure

Open rkorsak opened this issue 5 years ago • 4 comments

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.

rkorsak avatar Sep 18 '20 14:09 rkorsak

Interested please assgn

gagandeepp avatar Oct 03 '21 11:10 gagandeepp

@gagandeepp you got it!

keithrfung avatar Oct 06 '21 15:10 keithrfung

@rkorsak how to reproduce this error? Also do we need to make changes for all the scenarios in this ticket?

gagandeepp avatar Oct 08 '21 08:10 gagandeepp

@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.

keithrfung avatar Oct 08 '21 16:10 keithrfung