Skip to content

Commit

Permalink
Add error handling for log_request
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickkwang committed Sep 22, 2021
1 parent 53ba5be commit bce9d16
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion strider/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,18 @@ def elide_curies(payload):

def log_request(r):
""" Serialize a httpx.Request object into a dict for logging """
data = r.read().decode()
# the request body can be cleared out by httpx under some circumstances
# let's not crash if that happens
try:
data = elide_curies(json.loads(data))
except Exception:
pass
return {
"method" : r.method,
"url" : str(r.url),
"headers" : dict(r.headers),
"data" : elide_curies(json.loads(r.read().decode()))
"data" : data
}

def log_response(r):
Expand Down

0 comments on commit bce9d16

Please sign in to comment.