Skip to content

Commit

Permalink
Exceptions (#85)
Browse files Browse the repository at this point in the history
* exceptions

* missing files

* release version
  • Loading branch information
felipao-mx authored Apr 19, 2022
1 parent 316042c commit d2eaaeb
Show file tree
Hide file tree
Showing 6 changed files with 1,241 additions and 2 deletions.
12 changes: 12 additions & 0 deletions cep/exc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CepError(Exception):
"""
Error interno del sitio web
https://www.banxico.org.mx/cep/
"""


class MaxRequestError(CepError):
"""
Máximo número de peticiones alcanzadas para
obtener el CEP de una transferencia
"""
17 changes: 16 additions & 1 deletion cep/transferencia.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@

import clabe
from lxml import etree
from requests import HTTPError

from .client import Client
from .cuenta import Cuenta
from .exc import CepError, MaxRequestError

MAX_REQUEST_ERROR_MESSAGE = (
b'Lo sentimos, pero ha excedido el número máximo '
b'de consultas en este portal'
)


@dataclass
Expand Down Expand Up @@ -36,7 +43,15 @@ def validar(
)
if not client:
return None
xml = cls._descargar(client, 'XML')

try:
xml = cls._descargar(client, 'XML')
except HTTPError as exc:
raise CepError from exc

if MAX_REQUEST_ERROR_MESSAGE in xml:
raise MaxRequestError

resp = etree.fromstring(xml)

ordenante = Cuenta.from_etree(resp.find('Ordenante'))
Expand Down
2 changes: 1 addition & 1 deletion cep/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.2.0.dev0'
__version__ = '0.2.0'
Loading

0 comments on commit d2eaaeb

Please sign in to comment.