Skip to content

Commit d2eaaeb

Browse files
authored
Exceptions (#85)
* exceptions * missing files * release version
1 parent 316042c commit d2eaaeb

File tree

6 files changed

+1241
-2
lines changed

6 files changed

+1241
-2
lines changed

cep/exc.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class CepError(Exception):
2+
"""
3+
Error interno del sitio web
4+
https://www.banxico.org.mx/cep/
5+
"""
6+
7+
8+
class MaxRequestError(CepError):
9+
"""
10+
Máximo número de peticiones alcanzadas para
11+
obtener el CEP de una transferencia
12+
"""

cep/transferencia.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,16 @@
44

55
import clabe
66
from lxml import etree
7+
from requests import HTTPError
78

89
from .client import Client
910
from .cuenta import Cuenta
11+
from .exc import CepError, MaxRequestError
12+
13+
MAX_REQUEST_ERROR_MESSAGE = (
14+
b'Lo sentimos, pero ha excedido el número máximo '
15+
b'de consultas en este portal'
16+
)
1017

1118

1219
@dataclass
@@ -36,7 +43,15 @@ def validar(
3643
)
3744
if not client:
3845
return None
39-
xml = cls._descargar(client, 'XML')
46+
47+
try:
48+
xml = cls._descargar(client, 'XML')
49+
except HTTPError as exc:
50+
raise CepError from exc
51+
52+
if MAX_REQUEST_ERROR_MESSAGE in xml:
53+
raise MaxRequestError
54+
4055
resp = etree.fromstring(xml)
4156

4257
ordenante = Cuenta.from_etree(resp.find('Ordenante'))

cep/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.2.0.dev0'
1+
__version__ = '0.2.0'

0 commit comments

Comments
 (0)