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

adding error handling to send method #15

Closed
wants to merge 2 commits into from
Closed

adding error handling to send method #15

wants to merge 2 commits into from

Conversation

btoews
Copy link

@btoews btoews commented Jul 18, 2012

There is no good way of catching or dealing with exceptions that are raised during the request sending process when using map or imap. For example, I am writing a script to test it webservers are up. If a ConnectionError is raised I wouldn't be able to do anything about it. This commit adds an exception_handler parameter to the map,imap, and send 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:

import grequests

def eh(request,exception):
    print "couldn't request %s because of exception: %s" % (request.url,exception.__class__.__name__)

req  = grequests.get('http://127.0.0.1:123')
res  = grequests.map([req],exception_handler=eh)

@piotr-dobrogost
Copy link

Somehow related #6

This was referenced Sep 19, 2012
@kennethreitz
Copy link
Collaborator

Hmm, this is an interesting approach.

@btoews
Copy link
Author

btoews commented Feb 4, 2013

better addressed by #22

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.

None yet

3 participants