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

Add handling for exceptions raised by requests library #123

Merged
merged 3 commits into from
Oct 25, 2017

Conversation

non-Jedi
Copy link
Collaborator

@non-Jedi non-Jedi commented Apr 24, 2017

Use of requests is an implementation detail, so we shouldn't let exceptions raised by requests leak through to any application developers.

Technically this may need a major version bump since someone may have been manually handling exceptions raised by requests. But I doubt it.

@matrixbot
Copy link
Member

Can one of the admins verify this patch?

@Half-Shot
Copy link
Collaborator

ok to test

@Half-Shot
Copy link
Collaborator

I feel like this could perhaps do more. Do you think it would be possible for the exception to contain more details about the request that failed? Perhaps the endpoint that it tried to request?

Other than that, this looks fine.

@non-Jedi
Copy link
Collaborator Author

non-Jedi commented May 4, 2017

Done. Let me know if you'd like even more info than that included. Given that the circumstances where requests would raise an exception for one matrix endpoint but not another are relatively rare, I think this should be sufficient along with the traceback for debugging.

@Half-Shot Half-Shot self-requested a review May 5, 2017 07:53
)
except requests.exceptions.RequestException as e:
raise MatrixHttpLibError(
"Something went wrong in {} requesting {}".format(method, endpoint), e
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personal preference is to pass in method and endpoint as parameters to the exception and format it inside the constructor, in case I might want to disassemble it as a handler down the line.

@Half-Shot
Copy link
Collaborator

Other than that, LGTM 👍

@4nd3r
Copy link

4nd3r commented Oct 17, 2017

can we merge this?

using this sdk, without able to catch exceptions by requests library, is really annoying :<

@lugino-emeritus
Copy link

We should also add the request-timeout to this pull request (see #157)

@non-Jedi
Copy link
Collaborator Author

@4nd3r apologies if absence of this is affecting things for you. I'll prioritize this one. As it stands right now, you could directly catch exceptions raised by requests.

@non-Jedi non-Jedi force-pushed the handle_requests_exceptions branch from 8081c31 to 10db977 Compare October 24, 2017 01:20
@non-Jedi non-Jedi merged commit 3982688 into matrix-org:master Oct 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants