Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android): catch all native errors #149

Merged
merged 2 commits into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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