Skip to content

Commit

Permalink
fix: handle transaction request failure
Browse files Browse the repository at this point in the history
When the transaction request fails, we get an error message that should be
handled as a string. However, we currently parse all responses as a JSON, which
leads to a `JSONDecodeError`.

Handle response failures gracefully by checking if the request failed, and
returning the appropriate response.
  • Loading branch information
gabrielwong159 committed Sep 21, 2024
1 parent b2ae8d3 commit ce53516
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions apis/front/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ def get_transactions(username: str, password: str, demo: bool) -> list:
headers = {'Content-Type': 'application/json'}
data = json.dumps({'username': username, 'password': password})
req = requests.post(url, headers=headers, data=data)
if not req.ok:
return []
transactions = json.loads(req.text)
return transactions

Expand Down

0 comments on commit ce53516

Please sign in to comment.