Skip to content

Commit

Permalink
Retry on API error code 500 (custom-components#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
sveinse committed Aug 8, 2024
1 parent b917506 commit 827e94b
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

## 0.7.2b1

* Add retry on 500 server errors from Zaptec cloud, #90
* Reduce the amount of logging from the API, #90
* Delete old stale devices, #89
* Changed "total_charger_power_session" to TOTAL, #87
12 changes: 9 additions & 3 deletions custom_components/zaptec/api.py
Original file line number Diff line number Diff line change
@@ -975,13 +975,19 @@ async def _request(self, url: str, method="get", data=None):

return json_result

raise log_exc(
RequestError(
error = RequestError(
f"{method.upper()} request to {full_url} failed with status {resp.status}: {resp}",
resp.status,
)
)

if resp.status == 500: # Internal server error
# Zaptec cloud often delivers this error code.
log_exc(error) # Error is not raised, this for logging
continue # Retry request

# All other error codes will be raised
raise log_exc(error)

# API METHODS DONE
# =======================================================================

0 comments on commit 827e94b

Please sign in to comment.