From 5981622f3aa72289a9d1689c2a227d6516526b84 Mon Sep 17 00:00:00 2001 From: Ibby Hadeed Date: Tue, 10 Jan 2017 07:06:44 -0500 Subject: [PATCH] chore(): replace try/catch with better approach (#956) * chore(): replace try/catch with better approach * optimize last commit --- src/plugins/plugin.ts | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/plugins/plugin.ts b/src/plugins/plugin.ts index eea6f2290..26c846372 100644 --- a/src/plugins/plugin.ts +++ b/src/plugins/plugin.ts @@ -108,7 +108,7 @@ function callCordovaPlugin(pluginObj: any, methodName: string, args: any[], opts let pluginInstance = getPlugin(pluginObj.pluginRef); - if (!pluginInstance) { + if (!pluginInstance || !pluginInstance.hasOwnProperty(methodName)) { // Do this check in here in the case that the Web API for this plugin is available (for example, Geolocation). if (!window.cordova) { cordovaWarn(pluginObj.pluginName, methodName); @@ -123,16 +123,7 @@ function callCordovaPlugin(pluginObj: any, methodName: string, args: any[], opts }; } - // TODO: Illegal invocation needs window context - let value; - try { - value = get(window, pluginObj.pluginRef)[methodName].apply(pluginInstance, args); - } catch (e) { - value = { - error: 'cordova_not_available' - }; - } - return value; + return pluginInstance[methodName].apply(pluginInstance, args); } /**