1414import com .facebook .react .bridge .ReadableMap ;
1515import com .facebook .react .bridge .ReadableMapKeySetIterator ;
1616import com .facebook .react .bridge .ReadableNativeMap ;
17- import com .facebook .react .bridge .WritableMap ;
1817import com .facebook .react .bridge .WritableNativeArray ;
1918import com .facebook .react .bridge .WritableNativeMap ;
2019import com .thunderhead .mobile .One ;
@@ -97,39 +96,16 @@ public void sendInteraction(String interactionPath, ReadableMap propertiesMap, f
9796 response = One .sendInteraction (THROW_ERRORS , sendInteractionRequest ).join ();
9897 WritableNativeMap responseMap = responseObjectToReadableMap (response );
9998 notifyResult (promise , responseMap );
100- } catch (ExecutionException error ) {
101- notifyProblem (promise , Integer .toString (error .hashCode ()), Objects .requireNonNull (error .getCause ()).getLocalizedMessage ());
102- Log .e (NAME , "[Thunderhead] Send Interaction Completion Error: " + error .getCause ());
103- } catch (OneSDKError error ) {
104- notifyProblem (promise , Integer .toString (error .getSystemCode ()), error .getLocalizedMessage ());
105- Log .e (NAME , "[Thunderhead] Send Interaction SDK Error: " + error .getErrorMessage ());
106- } catch (OneAPIError error ) {
107- notifyProblem (promise , Integer .toString (error .getHttpStatusCode ()), error .getLocalizedMessage ());
108- Log .e (NAME , "[Thunderhead] Send Interaction Api Error: " + error .getErrorMessage ());
109- } catch (CompletionException error ) {
110- notifyProblem (promise , Integer .toString (error .hashCode ()), Objects .requireNonNull (error .getCause ()).getLocalizedMessage ());
111- Log .e (NAME , "[Thunderhead] Send Interaction Completion Error: " + error .getLocalizedMessage ());
11299 } catch (Exception error ) {
113- notifyProblem (promise , Integer .toString (error .hashCode ()), error .getLocalizedMessage ());
114- Log .e (NAME , "[Thunderhead] Send Interaction Error: " + error .getLocalizedMessage ());
100+ notifyProblem (promise , "Send Interaction" , error );
115101 }
116102 } else {
117103 try {
118104 response = One .sendInteractionLegacySupport (THROW_ERRORS , sendInteractionRequest ).join ();
119105 WritableNativeMap responseMap = responseObjectToReadableMap (response );
120106 notifyResult (promise , responseMap );
121- } catch (ExecutionException error ) {
122- notifyProblem (promise , Integer .toString (error .hashCode ()), Objects .requireNonNull (error .getCause ()).getLocalizedMessage ());
123- Log .e (NAME , "[Thunderhead] Send Interaction Completion Error: " + error .getCause ());
124- } catch (OneSDKError error ) {
125- notifyProblem (promise , Integer .toString (error .getSystemCode ()), error .getLocalizedMessage ());
126- Log .e (NAME , "[Thunderhead] Send Interaction SDK Error: " + error .getErrorMessage ());
127- } catch (OneAPIError error ) {
128- notifyProblem (promise , Integer .toString (error .getHttpStatusCode ()), error .getLocalizedMessage ());
129- Log .e (NAME , "[Thunderhead] Send Interaction Api Error: " + error .getErrorMessage ());
130107 } catch (Exception error ) {
131- notifyProblem (promise , Integer .toString (error .hashCode ()), error .getLocalizedMessage ());
132- Log .e (NAME , "[Thunderhead] Send Interaction Error: " + error .getLocalizedMessage ());
108+ notifyProblem (promise , "Send Interaction" , error );
133109 }
134110 }
135111 WritableNativeMap responseMap = responseObjectToReadableMap (response );
@@ -151,40 +127,17 @@ public void sendProperties(String interactionPath, ReadableMap propertiesMap, fi
151127 response = One .sendProperties (THROW_ERRORS , sendPropertiesRequest ).join ();
152128 WritableNativeMap responseMap = responseObjectToReadableMap (response );
153129 notifyResult (promise , responseMap );
154- } catch (ExecutionException error ) {
155- notifyProblem (promise , Integer .toString (error .hashCode ()), Objects .requireNonNull (error .getCause ()).getLocalizedMessage ());
156- Log .e (NAME , "[Thunderhead] Send Properties Completion Error: " + error .getCause ());
157- } catch (OneSDKError error ) {
158- notifyProblem (promise , Integer .toString (error .getSystemCode ()), error .getLocalizedMessage ());
159- Log .e (NAME , "[Thunderhead] Send Properties SDK Error: " + error .getErrorMessage ());
160- } catch (OneAPIError error ) {
161- notifyProblem (promise , Integer .toString (error .getHttpStatusCode ()), error .getLocalizedMessage ());
162- Log .e (NAME , "[Thunderhead] Send Properties Api Error: " + error .getErrorMessage ());
163- } catch (CompletionException error ) {
164- notifyProblem (promise , Integer .toString (error .hashCode ()), Objects .requireNonNull (error .getCause ()).getLocalizedMessage ());
165- Log .e (NAME , "[Thunderhead] Send Properties Completion Error: " + error .getCause ());
166130 } catch (Exception error ) {
167- notifyProblem (promise , Integer .toString (error .hashCode ()), error .getLocalizedMessage ());
168- Log .e (NAME , "[Thunderhead] Send Interaction Error: " + error .getLocalizedMessage ());
131+ notifyProblem (promise , "Send Properties" , error );
169132 }
170133 } else {
171134 try {
172135 OneResponse response ;
173136 response = One .sendPropertiesLegacySupport (THROW_ERRORS , sendPropertiesRequest ).join ();
174137 WritableNativeMap responseMap = responseObjectToReadableMap (response );
175138 notifyResult (promise , responseMap );
176- } catch (ExecutionException error ) {
177- notifyProblem (promise , Integer .toString (error .hashCode ()), Objects .requireNonNull (error .getCause ()).getLocalizedMessage ());
178- Log .e (NAME , "[Thunderhead] Send Properties Completion Error: " + error .getCause ());
179- } catch (OneSDKError error ) {
180- notifyProblem (promise , Integer .toString (error .getSystemCode ()), error .getLocalizedMessage ());
181- Log .e (NAME , "[Thunderhead] Send Properties SDK Error: " + error .getErrorMessage ());
182- } catch (OneAPIError error ) {
183- notifyProblem (promise , Integer .toString (error .getHttpStatusCode ()), error .getLocalizedMessage ());
184- Log .e (NAME , "[Thunderhead] Send Properties Api Error: " + error .getErrorMessage ());
185139 } catch (Exception error ) {
186- notifyProblem (promise , Integer .toString (error .hashCode ()), error .getLocalizedMessage ());
187- Log .e (NAME , "[Thunderhead] Send Interaction Error: " + error .getLocalizedMessage ());
140+ notifyProblem (promise , "Send Properties" , error );
188141 }
189142 }
190143 });
@@ -201,41 +154,17 @@ public void sendResponseCode(String interactionPath, String responseCode, final
201154 try {
202155 One .sendResponseCode (THROW_ERRORS , responseCodeRequest ).join ();
203156 notifyResult (promise , null );
204- } catch (ExecutionException error ) {
205- notifyProblem (promise , Integer .toString (error .hashCode ()), Objects .requireNonNull (error .getCause ()).getLocalizedMessage ());
206- Log .e (NAME , "[Thunderhead] Send Response Code Completion Error: " + error .getCause ());
207- } catch (OneSDKError error ) {
208- notifyProblem (promise , Integer .toString (error .getSystemCode ()), error .getLocalizedMessage ());
209- Log .e (NAME , "[Thunderhead] Send Response Code SDK Error: " + error .getErrorMessage ());
210- } catch (OneAPIError error ) {
211- notifyProblem (promise , Integer .toString (error .getHttpStatusCode ()), error .getLocalizedMessage ());
212- Log .e (NAME , "[Thunderhead] Send Response Code Api Error: " + error .getErrorMessage ());
213- } catch (CompletionException error ) {
214- notifyProblem (promise , Integer .toString (error .hashCode ()), Objects .requireNonNull (error .getCause ()).getLocalizedMessage ());
215- Log .e (NAME , "[Thunderhead] Send Properties Completion Error: " + error .getCause ());
216157 } catch (Exception error ) {
217- notifyProblem (promise , Integer .toString (error .hashCode ()), error .getLocalizedMessage ());
218- Log .e (NAME , "[Thunderhead] Send Interaction Error: " + error .getLocalizedMessage ());
158+ notifyProblem (promise , "Send Response Code" , error );
219159 }
220160 } else {
221161 try {
222162 One .sendResponseCodeLegacySupport (THROW_ERRORS , responseCodeRequest ).join ();
223163 notifyResult (promise , null );
224- } catch (ExecutionException error ) {
225- notifyProblem (promise , Integer .toString (error .hashCode ()), Objects .requireNonNull (error .getCause ()).getLocalizedMessage ());
226- Log .e (NAME , "[Thunderhead] Send Response Code Completion Error: " + error .getCause ());
227- } catch (OneSDKError error ) {
228- notifyProblem (promise , Integer .toString (error .getSystemCode ()), error .getLocalizedMessage ());
229- Log .e (NAME , "[Thunderhead] Send Response Code SDK Error: " + error .getErrorMessage ());
230- } catch (OneAPIError error ) {
231- notifyProblem (promise , Integer .toString (error .getHttpStatusCode ()), error .getLocalizedMessage ());
232- Log .e (NAME , "[Thunderhead] Send Response Code Api Error: " + error .getErrorMessage ());
233164 } catch (Exception error ) {
234- notifyProblem (promise , Integer .toString (error .hashCode ()), error .getLocalizedMessage ());
235- Log .e (NAME , "[Thunderhead] Send Interaction Error: " + error .getLocalizedMessage ());
165+ notifyProblem (promise , "Send Response Code" , error );
236166 }
237167 }
238-
239168 });
240169 }
241170
@@ -371,9 +300,22 @@ private void notifyProblem(Promise promise, Throwable throwable) {
371300 }
372301 }
373302
374- private void notifyProblem (Promise promise , String code , String message ) {
303+ private void notifyProblem (Promise promise , String message , Throwable throwable ) {
304+ String fullErrorMessage ;
305+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N && throwable instanceof CompletionException ) {
306+ fullErrorMessage = message + " ExecutionException Error" ;
307+ } else if (throwable instanceof OneSDKError ) {
308+ fullErrorMessage = message + " OneSDKError Error" ;
309+ } else if (throwable instanceof OneAPIError ) {
310+ fullErrorMessage = message + " OneAPIError Error" ;
311+ } else if (throwable instanceof ExecutionException ) {
312+ fullErrorMessage = message + " ExecutionException Error" ;
313+ } else {
314+ fullErrorMessage = message + " Error" ;
315+ }
375316 try {
376- promise .reject (code , message , (WritableMap ) null );
317+ promise .reject (OneModule .NAME , fullErrorMessage , throwable );
318+ Log .e (OneModule .NAME , fullErrorMessage , throwable );
377319 } catch (RuntimeException e ) {
378320 e .printStackTrace ();
379321 }
0 commit comments