Skip to content

Commit

Permalink
reports: Improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
malmeloo committed Jul 11, 2024
1 parent 740bbf0 commit af2ba33
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions findmy/reports/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,11 +614,15 @@ async def _do_request() -> HttpResponse:
msg = "Not authorized to fetch reports."
raise UnauthorizedError(msg)

if not r.ok or r.json()["statusCode"] != "200":
msg = f"Failed to fetch reports: {r.json()['statusCode']}"
try:
resp = r.json()
except json.JSONDecodeError:
resp = {}
if not r.ok or resp.get("statusCode") != "200":
msg = f"Failed to fetch reports: {resp.get('statusCode')}"
raise UnhandledProtocolError(msg)

return r.json()
return resp

@overload
async def fetch_reports(
Expand Down

0 comments on commit af2ba33

Please sign in to comment.