Open hbrls opened 11 years ago
It's a little tricky because of course each provider might format their errors differently. For instance, not all providers will return JSON. I'm not opposed to a more dynamic way of handing this though.
I like the way decoder
did it. I'm looking for a similar pattern. And how did you handle http errors? Handled by requestes
? There might be a hint.
@shuaishuai sure, feel free to make suggestions. I'm open to pull requests. :)
I was looking into this today - my API returns HTTP error responses properly, but those don't seem to be handled at all! I've hacked my local copy of service.py to throw a requests.exceptions.HTTPError if get_raw_request_token() doesn't get a 200 OK response - this seems to work pretty well for me.
I'm sure other APIs might have error responses you need to parse, but it seems like the very basics of HTTP require handling error responses - at least the 400s and 500s.
I'll continue and then make a pull request if there's interest. Not sure how we'd build unit tests either, without an actual web server..
The api may return error like this and cause
service.get_auth_session
not work because it did not have aaccess_token
key.I'm now handlng it in the decoder like this:
I think this is not elegant. But it's necessary because api errors are too frequent to ignore. Other than auth failed, the more common reasons might be "you're fetching this api too often" etc.
Will rauth handle this? Or I have to wrap rauth?