Enhance error handling in OxiAPI and Node classes

- Updated the `reload` method in the `OxiAPI` class to catch `HTTPError` exceptions and raise a custom `OxiAPIError` with context.
- Improved the `__call__` method in the `Node` class to handle `HTTPError` exceptions similarly, providing context-specific error messages.
- Introduced a new class method `from_http_error` in `OxiAPIError` for standardized error message generation based on HTTP status codes.
This commit is contained in:
IluaAir
2026-03-26 20:10:05 +03:00
parent 1cc225917e
commit 0b92e342e5
3 changed files with 42 additions and 10 deletions

View File

@@ -1,7 +1,8 @@
from typing import Optional
from requests import Session
from requests import HTTPError, Session
from oxi.adapter import OxiAdapter
from oxi.exception import OxiAPIError
from .node import Node
@@ -42,6 +43,9 @@ class OxiAPI:
return self._session.close()
def reload(self):
reload_response = self._session.get(f"{self.base_url}/reload")
reload_response.raise_for_status()
try:
reload_response = self._session.get(f"{self.base_url}/reload")
reload_response.raise_for_status()
except HTTPError as e:
raise OxiAPIError.from_http_error(e, context="Reload Oxidized") from e
return reload_response.status_code