Skip to content

Commit

Permalink
Merge pull request #52 from felixnext/felixnext/24-06_fail-easy
Browse files Browse the repository at this point in the history
Fail protobuf parsing easier
  • Loading branch information
felixnext authored Jun 26, 2024
2 parents c7a80a0 + 8ec1bbe commit ecfc883
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion functown/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "2.3.0"
__version__ = "2.3.1"

import logging

Expand Down
8 changes: 7 additions & 1 deletion functown/serialization/protobuf.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,13 @@ def deserialize(self, req: HttpRequest, *args, **kwargs) -> Any:
if isinstance(body, str):
body = body.encode("utf-8")
pb_item = self._pb_class()
json_format.Parse(body, pb_item)
# NOTE: this provides more graceful error handling
try:
json_format.Parse(body, pb_item)
except json_format.ParseError as e:
raise RequestError(f"Failed to parse JSON request: {str(e)}", 400)
except Exception as e:
raise RequestError(f"Error while parsing json body", 400)
return pb_item

# check for hard request
Expand Down

0 comments on commit ecfc883

Please sign in to comment.