forked from arnesson/cordova-plugin-firebase
-
-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ability to log JS stacktraces. #57 (Picked from https://github.…
- Loading branch information
1 parent
a7ae1dd
commit e2e32fe
Showing
5 changed files
with
106 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.apache.cordova.firebase; | ||
|
||
import org.json.JSONArray; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
/** | ||
* Exception class to log Javascript based exceptions with stacktrace. | ||
* | ||
* Picked from https://github.com/wizpanda/cordova-plugin-firebase-lib/pull/8/files | ||
* | ||
* @author https://github.com/sagrawal31/ | ||
*/ | ||
public class JavaScriptException extends Exception { | ||
|
||
public JavaScriptException(String message) { | ||
super(message); | ||
} | ||
|
||
public JavaScriptException(String message, JSONArray stackTrace) throws JSONException { | ||
super(message); | ||
this.handleStacktrace(stackTrace); | ||
} | ||
|
||
private void handleStacktrace(JSONArray stackTrace) throws JSONException { | ||
if (stackTrace == null) { | ||
return; | ||
} | ||
|
||
StackTraceElement[] trace = new StackTraceElement[stackTrace.length()]; | ||
|
||
for (int i = 0; i < stackTrace.length(); i++) { | ||
JSONObject elem = stackTrace.getJSONObject(i); | ||
|
||
trace[i] = new StackTraceElement( | ||
"undefined", | ||
elem.optString("functionName", "undefined"), | ||
elem.optString("fileName", "undefined"), | ||
elem.optInt("lineNumber", -1) | ||
); | ||
} | ||
|
||
this.setStackTrace(trace); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters