Skip to content

Commit

Permalink
Fix status handler documentation, use function instead of lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjacob committed Aug 19, 2024
1 parent e2e24a3 commit 02b76c1
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions docs/quick.rst
Original file line number Diff line number Diff line change
Expand Up @@ -247,21 +247,27 @@ throw an `APIStatusError`.

.. note::

`status_handler` is called with two arguments:
the status code and the entire `response.json()` object.
`status_handler` is called with three arguments:
the client instance, the status code, and the entire
`response.json()` object. Use `@staticmethod` if needed.

::

@staticmethod
def my_handler(error_code, response):
raise ValueError(error_code)


@api_client('https://example.org', status_key='status',
status_handler=lambda x, r: raise MyCustomError(x))
status_handler=my_handler)
class MyClient:
...
...

>>> client = MyClient()
>>> client.fetch_profile() # Server response: {'status': '404'}
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
MyCustomError(404)
ValueError(404)


Session/Cookies
Expand Down

0 comments on commit 02b76c1

Please sign in to comment.