Skip to content

Commit

Permalink
fix(android): catch all native errors (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
robingenz authored Jul 15, 2022
1 parent 4a0e4df commit c8543f6
Show file tree
Hide file tree
Showing 7 changed files with 524 additions and 302 deletions.
10 changes: 10 additions & 0 deletions .changeset/wise-rivers-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@capacitor-firebase/analytics": patch
"@capacitor-firebase/app": patch
"@capacitor-firebase/authentication": patch
"@capacitor-firebase/crashlytics": patch
"@capacitor-firebase/messaging": patch
"@capacitor-firebase/performance": patch
---

fix(android): catch all native errors and pass to the webview
Original file line number Diff line number Diff line change
Expand Up @@ -21,59 +21,83 @@ public void load() {

@PluginMethod
public void setUserId(PluginCall call) {
String userId = call.getString("userId", null);
implementation.setUserId(userId);
call.resolve();
try {
String userId = call.getString("userId", null);
implementation.setUserId(userId);
call.resolve();
} catch (Exception ex) {
call.reject(ex.getLocalizedMessage());
}
}

@PluginMethod
public void setUserProperty(PluginCall call) {
String key = call.getString("key");
if (key == null) {
call.reject(ERROR_KEY_MISSING);
return;
try {
String key = call.getString("key");
if (key == null) {
call.reject(ERROR_KEY_MISSING);
return;
}
String value = call.getString("value", null);
implementation.setUserProperty(key, value);
call.resolve();
} catch (Exception ex) {
call.reject(ex.getLocalizedMessage());
}
String value = call.getString("value", null);
implementation.setUserProperty(key, value);
call.resolve();
}

@PluginMethod
public void setCurrentScreen(PluginCall call) {
String screenName = call.getString("screenName", null);
String screenClassOverride = call.getString("screenClassOverride", null);
implementation.setCurrentScreen(screenName, screenClassOverride);
call.resolve();
try {
String screenName = call.getString("screenName", null);
String screenClassOverride = call.getString("screenClassOverride", null);
implementation.setCurrentScreen(screenName, screenClassOverride);
call.resolve();
} catch (Exception ex) {
call.reject(ex.getLocalizedMessage());
}
}

@PluginMethod
public void logEvent(PluginCall call) {
String name = call.getString("name");
if (name == null) {
call.reject(ERROR_NAME_MISSING);
return;
try {
String name = call.getString("name");
if (name == null) {
call.reject(ERROR_NAME_MISSING);
return;
}
JSObject params = call.getObject("params");
implementation.logEvent(name, params);
call.resolve();
} catch (Exception ex) {
call.reject(ex.getLocalizedMessage());
}
JSObject params = call.getObject("params");
implementation.logEvent(name, params);
call.resolve();
}

@PluginMethod
public void setSessionTimeoutDuration(PluginCall call) {
Long duration = call.getLong("duration", 1800000L);
implementation.setSessionTimeoutDuration(duration);
call.resolve();
try {
Long duration = call.getLong("duration", 1800000L);
implementation.setSessionTimeoutDuration(duration);
call.resolve();
} catch (Exception ex) {
call.reject(ex.getLocalizedMessage());
}
}

@PluginMethod
public void setEnabled(PluginCall call) {
Boolean enabled = call.getBoolean("enabled");
if (enabled == null) {
call.reject(ERROR_ENABLED_MISSING);
return;
try {
Boolean enabled = call.getBoolean("enabled");
if (enabled == null) {
call.reject(ERROR_ENABLED_MISSING);
return;
}
implementation.setEnabled(enabled);
call.resolve();
} catch (Exception ex) {
call.reject(ex.getLocalizedMessage());
}
implementation.setEnabled(enabled);
call.resolve();
}

@PluginMethod
Expand All @@ -83,7 +107,11 @@ public void isEnabled(PluginCall call) {

@PluginMethod
public void resetAnalyticsData(PluginCall call) {
implementation.resetAnalyticsData();
call.resolve();
try {
implementation.resetAnalyticsData();
call.resolve();
} catch (Exception ex) {
call.reject(ex.getLocalizedMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,29 @@ public void load() {

@PluginMethod
public void getName(PluginCall call) {
JSObject ret = new JSObject();
ret.put("name", firebaseAppInstance.getName());
call.resolve(ret);
try {
JSObject ret = new JSObject();
ret.put("name", firebaseAppInstance.getName());
call.resolve(ret);
} catch (Exception ex) {
call.reject(ex.getLocalizedMessage());
}
}

@PluginMethod
public void getOptions(PluginCall call) {
FirebaseOptions options = firebaseAppInstance.getOptions();
JSObject ret = new JSObject();
ret.put("apiKey", options.getApiKey());
ret.put("applicationId", options.getApplicationId());
ret.put("databaseUrl", options.getDatabaseUrl());
ret.put("gcmSenderId", options.getGcmSenderId());
ret.put("projectId", options.getProjectId());
ret.put("storageBucket", options.getStorageBucket());
call.resolve(ret);
try {
FirebaseOptions options = firebaseAppInstance.getOptions();
JSObject ret = new JSObject();
ret.put("apiKey", options.getApiKey());
ret.put("applicationId", options.getApplicationId());
ret.put("databaseUrl", options.getDatabaseUrl());
ret.put("gcmSenderId", options.getGcmSenderId());
ret.put("projectId", options.getProjectId());
ret.put("storageBucket", options.getStorageBucket());
call.resolve(ret);
} catch (Exception ex) {
call.reject(ex.getLocalizedMessage());
}
}
}
Loading

0 comments on commit c8543f6

Please sign in to comment.