-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle ConnectTimeout exceptions in _call method #115
Conversation
correios/client.py
Outdated
@@ -109,6 +110,8 @@ def _call(self, method_name, *args, **kwargs): | |||
method = getattr(self.sigep, method_name) | |||
try: | |||
return method(*args, **kwargs) | |||
except ConnectTimeout: | |||
raise ConnectTimeoutError | |||
except Fault as exc: | |||
if 'autenticacao' in str(exc): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
esse é o único/melhor jeito de ver se é um erro de autenticação? não tem nenhum atributo onde eu consiga pegar um código ou a mensagem dentro do objeto exc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, executing some tests with SoapClient, to check authentications problems, I just get a Fault exception like this:
Fault: A autenticacao de sigep falhou!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a parte massa é que quando acontece erro de autenticação a API dos correios retorna código 500
ao invés de 40x 🔝 💯 🎉
correios/client.py
Outdated
@@ -109,6 +110,8 @@ def _call(self, method_name, *args, **kwargs): | |||
method = getattr(self.sigep, method_name) | |||
try: | |||
return method(*args, **kwargs) | |||
except ConnectTimeout: | |||
raise ConnectTimeoutError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
raise ConnectTimeoutError(f"Timeout connection error ({self.timeout} seconds)")
Sempre levantamos exceptions como instâncias e não classes. É o momento de informar o usuário detalhes do problema...
Done @osantana |
except Fault as exc: | ||
if 'autenticacao' in str(exc): | ||
raise AuthenticationError | ||
if "autenticacao" in str(exc): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Algum motivo das aspas duplas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to follow a pattern. I prefer single quotes but almost all the file use double quotes.
Create a ConnectTimeoutError in correios lib to handle ConnectTimeout errors from requests lib.