Skip to content

Commit

Permalink
Pass response in status handler
Browse files Browse the repository at this point in the history
This change makes it possible to handle specific scenarios better
  • Loading branch information
sanjacob committed Aug 11, 2024
1 parent 101bb83 commit 48ab9ee
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tests/test_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,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):
def throw_custom(error_code, response):
raise ValueError(error_code)

@api_client(example_url, status_key='custom_error',
Expand Down
4 changes: 2 additions & 2 deletions tiny_api_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
P = ParamSpec('P')
T = TypeVar('T')

APIStatusHandler = Callable[[Any], None] | None
APIStatusHandler = Callable[[Any, Any], None] | None
APIClient = TypeVar('APIClient', bound=type[Any])


Expand Down Expand Up @@ -174,7 +174,7 @@ def _handle_response(response: Any,
_logger.warning(f"Code {status_code} from {response.url}")

if status_handler is not None:
status_handler(status_code)
status_handler(status_code, endpoint_response)
else:
raise APIStatusError('Server responded with an error code')

Expand Down

0 comments on commit 48ab9ee

Please sign in to comment.