feat: Add retry logic and logging for POST request failures in BaseAPI
This commit is contained in:
@@ -7,7 +7,7 @@ from limit import limit # type:ignore
|
||||
import loguru
|
||||
import sys
|
||||
import json
|
||||
|
||||
import time
|
||||
log = loguru.logger
|
||||
log.remove()
|
||||
log.add("logs/komga_api.log", rotation="1 week", retention="1 month")
|
||||
@@ -96,18 +96,27 @@ class BaseAPI:
|
||||
json.dumps(data),
|
||||
json.dumps(body),
|
||||
)
|
||||
response.raise_for_status()
|
||||
status_code = response.status_code
|
||||
if status_code == 202:
|
||||
return None
|
||||
elif status_code == 200:
|
||||
return response.json()
|
||||
else:
|
||||
raise ResultErrror(f"Result Error: {response.content}")
|
||||
time.sleep(10)
|
||||
log.error(
|
||||
"Unexpected status code {} during POST to {}: {}",
|
||||
status_code,
|
||||
url,
|
||||
response.text,
|
||||
)
|
||||
return self.postRequest(url, data, body)
|
||||
except httpx.ConnectError as e:
|
||||
raise KomgaError(f"Connection Error: {e}") from e
|
||||
except httpx.TimeoutException as e:
|
||||
raise KomgaError(f"Timeout Error: {e}") from e
|
||||
time.sleep(5) # Wait before retrying
|
||||
log.error("Timeout during POST to {}: {}", url, str(e))
|
||||
|
||||
# raise KomgaError(f"Timeout Error: {e}") from e
|
||||
|
||||
def patchRequest(self, url: str, data: Union[dict[Any, Any], None] = None):
|
||||
"""Send PATCH request to API endpoint.
|
||||
|
||||
Reference in New Issue
Block a user