Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Return JSON Error message from facebook, this is useful to some funct…

…ional logics, ex,: in some cases like missing some keys in dict like actions, actions need ("name", "link") keys, if you miss facebook return the error message.
  • Loading branch information...
commit 2e5dfd7974e80182c0bdbc2e24a5e13cd566855b 1 parent bcbef8c
@wsantos authored
Showing with 32 additions and 2 deletions.
  1. +32 −2 tornado/auth.py
View
34 tornado/auth.py
@@ -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))
Please sign in to comment.
Something went wrong with that request. Please try again.