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:
10
oxi/core.py
10
oxi/core.py
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user