Skip to content

Commit

Permalink
Add new requests exceptions
Browse files Browse the repository at this point in the history
Add exceptions to encapsulte request exceptions and improve docs
  • Loading branch information
mstuttgart committed Nov 25, 2024
1 parent be76981 commit d4a03d2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
20 changes: 20 additions & 0 deletions brazilcep/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,23 @@ class CEPNotFound(BrazilCEPException):

class BlockedByFlood(BrazilCEPException):
"""Exception raised by flood of requests"""


class ConnectionError(BrazilCEPException):
"""Exception raised by a connection error"""


class HTTPError(BrazilCEPException):
"""Exception raised by HTTP error"""


class URLRequired(BrazilCEPException):
"""Exception raised by using a invalid URL to make a request"""


class TooManyRedirects(BrazilCEPException):
"""Exception raised by too many redirects"""


class Timeout(BrazilCEPException):
"""Exception raised by request timed out"""
8 changes: 5 additions & 3 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ Exceptions
----------

.. autoexception:: brazilcep.exceptions.BrazilCEPException
.. autoexception:: brazilcep.exceptions.ConnectionError
.. autoexception:: brazilcep.exceptions.HTTPError
.. autoexception:: brazilcep.exceptions.URLRequired
.. autoexception:: brazilcep.exceptions.TooManyRedirects
.. autoexception:: brazilcep.exceptions.Timeout
.. autoexception:: brazilcep.exceptions.InvalidCEP
.. autoexception:: brazilcep.exceptions.CEPNotFound
.. autoexception:: brazilcep.exceptions.BlockedByFlood
Expand Down Expand Up @@ -72,8 +77,5 @@ This is the new code::

The follow `Exceptions` have been removed:

* `ConnectionError`
* `Timeout`
* `HTTPError`
* `BaseException`

20 changes: 14 additions & 6 deletions docs/source/user/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,21 @@ Errors and Exceptions
BrazilCEP also supports a group of exceptions that can be used to
handle any errors that occur during the query process.

If a invalid CEP request has be made, a :exc:`~brazilcep.exceptions.InvalidCEP` exception is
raised.
:exc:`~brazilcep.exceptions.InvalidCEP` exception raised by a request with invalid CEP.

If a CEP request not find CEP address, a :exc:`~brazilcep.exceptions.CEPNotFound` exception is raised.
:exc:`~brazilcep.exceptions.CEPNotFound` exception is raised when CEP is not find in selected API.

To a large number of CEP requests in short range of time, a :exc:`~brazilcep.exceptions.BlockedByFlood` exception is raised.
:exc:`~brazilcep.exceptions.BlockedByFlood`: exception raides by a large number of CEP requests in short range of time

All exceptions that BrazilCEP explicitly raises inherit from
:exc:`brazilcep.exceptions.BrazilCEPException`.
:exc:`~brazilcep.exceptions.ConnectionError`: exception raised by a connection error.

:exc:`~brazilcep.exceptions.HTTPError`: exception raised by HTTP error.

:exc:`~brazilcep.exceptions.URLRequired`: exception raised by using a invalid URL to make a CEP request.

:exc:`~brazilcep.exceptions.TooManyRedirects`: Exception raised by too many redirects.

:exc:`~brazilcep.exceptions.Timeout`: exception raised by request timed out.

All exceptions that BrazilCEP explicitly raises inherit from :exc:`brazilcep.exceptions.BrazilCEPException`.

0 comments on commit d4a03d2

Please sign in to comment.