Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry once in case of status 500 #105

Merged
merged 2 commits into from
Sep 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions ariston/ariston_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
from __future__ import annotations

import logging
import time
from typing import Any, Optional

import aiohttp
import asyncio
import requests

from .const import (
Expand Down Expand Up @@ -440,6 +442,10 @@ def __request(
raise Exception("Invalid token")
if response.status_code == 404:
return None
if response.status_code == 500:
if not is_retry:
time.sleep(1)
return self.__request(method, path, params, body, True)
raise Exception(response.status_code)

if len(response.content) > 0:
Expand Down Expand Up @@ -852,6 +858,12 @@ async def __async_request(
raise Exception("Invalid token")
if response.status == 404:
return None
if response.status == 500:
if not is_retry:
await asyncio.sleep(1)
return await self.__async_request(
method, path, params, body, True
)
raise Exception(response.status)

if response.content_length and response.content_length > 0:
Expand Down