diff --git a/docs/quick.rst b/docs/quick.rst index ae012d5..07385b2 100644 --- a/docs/quick.rst +++ b/docs/quick.rst @@ -249,12 +249,11 @@ throw an `APIStatusError`. `status_handler` is called with three arguments: the client instance, the status code, and the entire - `response.json()` object. Use `@staticmethod` if needed. + `response.json()` object. :: - @staticmethod - def my_handler(error_code, response): + def my_handler(client, error_code, response): raise ValueError(error_code) diff --git a/tests/test_api_client.py b/tests/test_api_client.py index 9113360..282bc33 100644 --- a/tests/test_api_client.py +++ b/tests/test_api_client.py @@ -335,8 +335,7 @@ def get_my_endpoint(self, response): def test_class_decorator_parameter_status_handler_throws(mock_requests, example_url): - @staticmethod - def throw_custom(error_code, response): + def throw_custom(client, error_code, response): raise ValueError(error_code) @api_client(example_url, status_key='custom_error', diff --git a/tiny_api_client/__init__.py b/tiny_api_client/__init__.py index b017648..537d629 100644 --- a/tiny_api_client/__init__.py +++ b/tiny_api_client/__init__.py @@ -52,6 +52,8 @@ T = TypeVar('T') APIStatusHandler = Callable[[Any, Any, Any], None] | None +_StatusHandler = Callable[[Any, Any], None] | None + APIClient = TypeVar('APIClient', bound=type[Any]) @@ -159,7 +161,7 @@ def _make_request(client: Any, method: str, endpoint: str, def _handle_response(response: Any, json: bool, xml: bool, status_key: str, results_key: str, - status_handler: APIStatusHandler) -> Any: + status_handler: _StatusHandler) -> Any: """Parse json or XML response after request is complete""" endpoint_response: Any = response