adding error handling to send method #15
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There is no good way of catching or dealing with exceptions that are raised during the request sending process when using
map
orimap
. For example, I am writing a script to test it webservers are up. If aConnectionError
is raised I wouldn't be able to do anything about it. This commit adds anexception_handler
parameter to themap
,imap
, andsend
methods. This callback gets called with the request and exception in the event of an exception being raised.I do this with gevent.greenlet.Greenlet.link_exception, but I am not sure that this is the best way of doing it. It would be nice if there was a way to catch exceptions rather than just linking to them. Have you thought about catching ConnectionError in
requests
and adjusting the response.error and whatnot accordingly?Here is an example use-case: