[Utils] Check if response is undefined in callSync 77/113677/1
authorJakub Skowron <j.skowron@samsung.com>
Wed, 8 Feb 2017 09:20:17 +0000 (10:20 +0100)
committerJakub Skowron <j.skowron@samsung.com>
Wed, 8 Feb 2017 09:20:17 +0000 (10:20 +0100)
If response is undefined JSON.parse(undefined) throws
'SyntaxError: Unexpected token u', and it goes to top-level.
It hides the real cause, which is internal error.

Change-Id: Icce09baf8ba007ce7bb754a4f4af89ce2014cd36
Signed-off-by: Jakub Skowron <j.skowron@samsung.com>
src/utils/utils_api.js

index 5502e3f2a46254c7e2da9d838bacd55be9aaab20..371045546056ce04f4d49762b3b14aa89ac6518a 100644 (file)
@@ -1076,7 +1076,12 @@ NativeManager.prototype.callSync = function(cmd, args) {
     args: args || {}
   });
 
-  return JSON.parse(this.extension.internal.sendSyncMessage(request));
+  var response = this.extension.internal.sendSyncMessage(request);
+  if( response === undefined ) {
+    /* C++ extension didn't set sync response using Instance::SendSyncReply */
+    throw new WebAPIException(WebAPIException.ABORT_ERR, "Internal error");
+  }
+  return JSON.parse(response);
 };
 
 NativeManager.prototype.sendRuntimeMessage = function(msg, body) {