Re: [Httplib2-discuss] httplib2 should provide custom exceptions for httplib failures
Status: Beta
Brought to you by:
jcgregorio
From: Igor F. <igo...@gm...> - 2006-12-12 18:13:35
|
On 12-Dec-06, at 12:41 PM, Joe Gregorio wrote: > On 12/8/06, Simon Willison <si...@si...> wrote: >> One solution might be for httplib2 to have two request methods - one >> that raises exceptions and one that returns the document with the >> non-200 status code. It would be nice if Python had a standard idiom >> or naming convention for pairs of methods like this, but it's not >> something I've seen anywhere. There might be a good reason for that >> of course. > > I'm thinking of at least making this a switch, on by default, that > turns > all exceptions into status codes. One of the big reasons for doing > do is > getting back information on failures. For example, if the number of > re-directs > exceeds the limit the caller may want to see the chain of response > objects when debugging. The best way to accommodate that is to return > a response and not throw an exception. > > This would be a Http property like 'follow_all_redirects'. I'm not entirely sure that it makes sense for _all_ exceptions, but such a switch would definitely be useful in a lot of cases. Another possible way to do this is have the exception that httplib2 throws contain the response information in some format. The syntax of catching these conditions (404 not found, or infinte redirects) as exceptions makes a lot of sense, the important part is to be able to get at the underlying cause of the exception, and the chain of events that caused it. You also say that this is useful when debugging, but a situation like this isn't necessarily a failure, it could be an expected turn of events. Thanks, Igor |