2
2
3
3
import static com .instabug .reactlibrary .utils .InstabugUtil .getMethod ;
4
4
5
+ import androidx .annotation .NonNull ;
6
+
5
7
import com .facebook .react .bridge .Promise ;
6
8
import com .facebook .react .bridge .ReactApplicationContext ;
7
9
import com .facebook .react .bridge .ReactContextBaseJavaModule ;
8
10
import com .facebook .react .bridge .ReactMethod ;
11
+ import com .facebook .react .bridge .ReadableMap ;
9
12
import com .instabug .crash .CrashReporting ;
13
+ import com .instabug .crash .models .IBGNonFatalException ;
10
14
import com .instabug .library .Feature ;
11
15
import com .instabug .reactlibrary .utils .MainThreadHandler ;
12
16
13
17
import org .json .JSONObject ;
14
18
15
19
import java .lang .reflect .InvocationTargetException ;
16
20
import java .lang .reflect .Method ;
21
+ import java .util .HashMap ;
22
+ import java .util .Map ;
17
23
18
24
import javax .annotation .Nonnull ;
19
25
import javax .annotation .Nullable ;
@@ -57,8 +63,8 @@ public void run() {
57
63
* Send unhandled JS error object
58
64
*
59
65
* @param exceptionObject Exception object to be sent to Instabug's servers
60
- * @param promise This makes sure that the RN side crashes the app only after the Android SDK
61
- * finishes processing/handling the crash.
66
+ * @param promise This makes sure that the RN side crashes the app only after the Android SDK
67
+ * finishes processing/handling the crash.
62
68
*/
63
69
@ ReactMethod
64
70
public void sendJSCrash (final String exceptionObject , final Promise promise ) {
@@ -79,41 +85,64 @@ public void run() {
79
85
* Send handled JS error object
80
86
*
81
87
* @param exceptionObject Exception object to be sent to Instabug's servers
88
+ * @param userAttributes (Optional) extra user attributes attached to the crash
89
+ * @param fingerprint (Optional) key used to customize how crashes are grouped together
90
+ * @param level different severity levels for errors
82
91
*/
83
92
@ ReactMethod
84
- public void sendHandledJSCrash (final String exceptionObject ) {
93
+ public void sendHandledJSCrash (final String exceptionObject , @ Nullable ReadableMap userAttributes , @ Nullable String fingerprint , @ Nullable String level ) {
85
94
try {
86
95
JSONObject jsonObject = new JSONObject (exceptionObject );
87
- sendJSCrashByReflection (jsonObject , true , null );
88
- } catch (Exception e ) {
96
+ MainThreadHandler .runOnMainThread (new Runnable () {
97
+ @ Override
98
+ public void run () {
99
+ try {
100
+ Method method = getMethod (Class .forName ("com.instabug.crash.CrashReporting" ), "reportException" , JSONObject .class , boolean .class ,
101
+ Map .class , JSONObject .class , IBGNonFatalException .Level .class );
102
+ if (method != null ) {
103
+ IBGNonFatalException .Level nonFatalExceptionLevel = ArgsRegistry .nonFatalExceptionLevel .getOrDefault (level , IBGNonFatalException .Level .ERROR );
104
+ Map <String , Object > userAttributesMap = userAttributes == null ? null : userAttributes .toHashMap ();
105
+ JSONObject fingerprintObj = fingerprint == null ? null : CrashReporting .getFingerprintObject (fingerprint );
106
+
107
+ method .invoke (null , jsonObject , true , userAttributesMap , fingerprintObj , nonFatalExceptionLevel );
108
+
109
+ RNInstabugReactnativeModule .clearCurrentReport ();
110
+ }
111
+ } catch (ClassNotFoundException | IllegalAccessException |
112
+ InvocationTargetException e ) {
113
+ e .printStackTrace ();
114
+ }
115
+ }
116
+ });
117
+ } catch (Throwable e ) {
89
118
e .printStackTrace ();
90
119
}
91
120
}
92
121
93
- private void sendJSCrashByReflection (final JSONObject exceptionObject , final boolean isHandled , @ Nullable final Runnable onComplete ) {
94
- MainThreadHandler .runOnMainThread (new Runnable () {
95
- @ Override
96
- public void run () {
97
- try {
98
- Method method = getMethod (Class .forName ("com.instabug.crash.CrashReporting" ), "reportException" , JSONObject .class , boolean .class );
99
- if (method != null ) {
100
- method .invoke (null , exceptionObject , isHandled );
101
- RNInstabugReactnativeModule .clearCurrentReport ();
102
- }
103
- } catch (ClassNotFoundException e ) {
104
- e .printStackTrace ();
105
- } catch (IllegalAccessException e ) {
106
- e .printStackTrace ();
107
- } catch (InvocationTargetException e ) {
108
- e .printStackTrace ();
109
- } finally {
110
- if (onComplete != null ) {
111
- onComplete .run ();
112
- }
113
- }
114
- }
115
- });
116
- }
122
+ private void sendJSCrashByReflection (final JSONObject exceptionObject , final boolean isHandled , @ Nullable final Runnable onComplete ) {
123
+ MainThreadHandler .runOnMainThread (new Runnable () {
124
+ @ Override
125
+ public void run () {
126
+ try {
127
+ Method method = getMethod (Class .forName ("com.instabug.crash.CrashReporting" ), "reportException" , JSONObject .class , boolean .class );
128
+ if (method != null ) {
129
+ method .invoke (null , exceptionObject , isHandled );
130
+ RNInstabugReactnativeModule .clearCurrentReport ();
131
+ }
132
+ } catch (ClassNotFoundException e ) {
133
+ e .printStackTrace ();
134
+ } catch (IllegalAccessException e ) {
135
+ e .printStackTrace ();
136
+ } catch (InvocationTargetException e ) {
137
+ e .printStackTrace ();
138
+ } finally {
139
+ if (onComplete != null ) {
140
+ onComplete .run ();
141
+ }
142
+ }
143
+ }
144
+ });
145
+ }
117
146
118
147
/**
119
148
* Enables and disables capturing native C++ NDK crash reporting.
0 commit comments