mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-19 15:12:51 +08:00
Catch uncaught exceptions in from plugins and turn them into error responses.
When a plugin throws an unchecked exception, we're not catching it anywhere and so the error callback is not being called. This change adds a try/catch to catch such exceptions.
This commit is contained in:
parent
9f4c75d1c2
commit
79e313a0c0
@ -236,8 +236,8 @@ public class PluginManager {
|
|||||||
app.sendPluginResult(cr, callbackId);
|
app.sendPluginResult(cr, callbackId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
CallbackContext callbackContext = new CallbackContext(callbackId, app);
|
CallbackContext callbackContext = new CallbackContext(callbackId, app);
|
||||||
|
try {
|
||||||
long pluginStartTime = System.currentTimeMillis();
|
long pluginStartTime = System.currentTimeMillis();
|
||||||
boolean wasValidAction = plugin.execute(action, rawArgs, callbackContext);
|
boolean wasValidAction = plugin.execute(action, rawArgs, callbackContext);
|
||||||
long duration = System.currentTimeMillis() - pluginStartTime;
|
long duration = System.currentTimeMillis() - pluginStartTime;
|
||||||
@ -247,11 +247,14 @@ public class PluginManager {
|
|||||||
}
|
}
|
||||||
if (!wasValidAction) {
|
if (!wasValidAction) {
|
||||||
PluginResult cr = new PluginResult(PluginResult.Status.INVALID_ACTION);
|
PluginResult cr = new PluginResult(PluginResult.Status.INVALID_ACTION);
|
||||||
app.sendPluginResult(cr, callbackId);
|
callbackContext.sendPluginResult(cr);
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
PluginResult cr = new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
PluginResult cr = new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
||||||
app.sendPluginResult(cr, callbackId);
|
callbackContext.sendPluginResult(cr);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "Uncaught exception from plugin", e);
|
||||||
|
callbackContext.error(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user