Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Return JSON from facebook error if body has a json. #480

Closed
wants to merge 1 commit into
from
Jump to file or symbol
Failed to load files and symbols.
+32 −2
Split
View
@@ -1000,7 +1000,21 @@ def _on_access_token(self, redirect_uri, client_id, client_secret,
callback, fields, response):
if response.error:
logging.warning('Facebook auth error: %s' % str(response))
- callback(None)
+
+ try:
+ json = escape.json_decode(response.body)
+ except Exception:
+ logging.warning("Invalid JSON from Facebook: %r", response.body)
+ callback(None)
+ return
+
+ if isinstance(json, dict) and json.get("error_code"):
+ logging.warning("Facebook error: %d: %r", json["error_code"],
+ json.get("error_msg"))
+ callback(None)
+ return
+
+ callback(json)
return
args = escape.parse_qs_bytes(escape.native_str(response.body))
@@ -1084,8 +1098,24 @@ def _on_facebook_request(self, callback, response):
if response.error:
logging.warning("Error response %s fetching %s", response.error,
response.request.url)
- callback(None)
+
+ try:
+ json = escape.json_decode(response.body)
+ except Exception:
+ logging.warning("Invalid JSON from Facebook: %r", response.body)
+ callback(None)
+ return
+
+ if isinstance(json, dict) and json.get("error_code"):
+ logging.warning("Facebook error: %d: %r", json["error_code"],
+ json.get("error_msg"))
+ callback(None)
+ return
+
+ callback(json)
return
+
+
callback(escape.json_decode(response.body))