Skip to content
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

Merged
merged 3 commits into from
Feb 22, 2018

Conversation

bratomes
Copy link
Contributor

Create a ConnectTimeoutError in correios lib to handle ConnectTimeout errors from requests lib.

@@ -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):
Copy link
Contributor

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?

Copy link
Contributor Author

@bratomes bratomes Feb 22, 2018

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!

Copy link
Contributor

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 🔝 💯 🎉

@@ -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
Copy link
Contributor

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...

@bratomes
Copy link
Contributor Author

Done @osantana

except Fault as exc:
if 'autenticacao' in str(exc):
raise AuthenticationError
if "autenticacao" in str(exc):
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@lamenezes lamenezes merged commit d636fa3 into master Feb 22, 2018
@lamenezes lamenezes deleted the handle-timeout-error branch February 22, 2018 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants