Skip to content

Latest commit

 

History

History
41 lines (25 loc) · 1.3 KB

exceptions.rst

File metadata and controls

41 lines (25 loc) · 1.3 KB

Exceptions

Catching API errors

AioTapioca supports 2 main types of exceptions: ClientError and ServerError. The default implementation raises ClientError for HTTP response 4xx status codes and ServerError for 5xx status codes. Since each API has its own ways of reporting errors and not all of them follow HTTP recommendations for status codes, this can be overriden by each implemented client to reflect its behaviour. Both of these exceptions extend TapiocaException which can be used to catch errors in a more generic way.

Base class for aiotapioca exceptions. Example usage:

from aiotapioca.exceptions import TapiocaException

try:
        await cli.fetch_something().get()
except TapiocaException, e:
        print("API call failed with error %s", e.status_code)

You can also access a aiotapioca client that contains response data from the exception:

from aiotapioca.exceptions import TapiocaException

try:
        await cli.fetch_something().get()
except TapiocaException, e:
        print(e.client().data)

Default exception for client errors. Extends from TapiocaException.

Default exception for server errors. Extends from TapiocaException.