Skip to content

Commit

Permalink
fix buggy error_code check in logger
Browse files Browse the repository at this point in the history
  • Loading branch information
frostyfan109 committed Dec 18, 2024
1 parent 4afaa31 commit 07f1e46
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/core/middleware/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ async def dispatch(self, request: Request, call_next: Callable):
response.__setattr__("body_iterator", AsyncIteratorWrapper(resp_body))

try:
# Why is this resp_body[0]?
resp_body = json.loads(resp_body[0])
except:
resp_body = str(resp_body)

if "error_code" in resp_body:
if isinstance(resp_body, dict) and "error_code" in resp_body:
# If the response contains an error code, that means an exception happened
# and we need to log it. So just log the exception and return, don't log
# the request as you would normally.
Expand Down

0 comments on commit 07f1e46

Please sign in to comment.