Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail protobuf parsing easier #52

Merged
merged 5 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading