added error handling if token validation response is not a valid JSON string
authordurandn
Fri, 01 Apr 2016 12:56:16 +0200
changeset 43 425a2f1e08ea
parent 42 67b76cf4469e
child 44 1b2019523772
added error handling if token validation response is not a valid JSON string
server/src/metaeducation/auth.py
--- a/server/src/metaeducation/auth.py	Fri Apr 01 11:46:27 2016 +0200
+++ b/server/src/metaeducation/auth.py	Fri Apr 01 12:56:16 2016 +0200
@@ -42,7 +42,15 @@
         if token_validate_response.status_code != 200:
             logger.warning("CLIENT CREDENTIAL AUTH: Validation service didn't response with 200, there may be a problem")
             return
-        validate_response_json = json.loads(token_validate_response.text)
+        
+        try:
+            validate_response_json = json.loads(token_validate_response.text)
+        except json.JSONDecodeError as decode_error:
+            logger.warning("CLIENT CREDENTIAL AUTH: Token validate response was not a JSON!")
+            logger.warning("CLIENT CREDENTIAL AUTH: Tried to decode: %r", decode_error.doc)
+            logger.warning("CLIENT CREDENTIAL AUTH: Error message is %r", decode_error.msg)
+            return
+            
         
         # Response json validation
         if "access_token" not in validate_response_json.keys():