From c8a0bee59b45dcc96bdd5157814df527290d4ba4 Mon Sep 17 00:00:00 2001 From: Chris Pickett Date: Wed, 25 Apr 2012 11:24:13 -0500 Subject: [PATCH] Adds OAuthException exception and raises it when an OAuthException is recieved from Facebook. --- facepy/graph_api.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/facepy/graph_api.py b/facepy/graph_api.py index 515d95d..05925fb 100755 --- a/facepy/graph_api.py +++ b/facepy/graph_api.py @@ -230,11 +230,16 @@ def _parse(self, data): # We'll handle this discrepancy as gracefully as we can by implementing logic to deal with this behavior # in the high-level access functions (get, post, delete etc.). if type(data) is dict: - if 'error' in data: error = data['error'] + error_type = error.get('type') - raise self.FacebookError( + if error_type == "OAuthException": + exception = self.OAuthException + else: + exception = self.FacebookError + + raise exception( error.get('message'), error.get('code', None) ) @@ -254,5 +259,8 @@ def __init__(self, message, code): self.code = code + class OAuthException(FacebookError): + """ Exception for errors specifically related to OAuth. """ + class HTTPError(FacepyError): """Exception for transport errors."""