4040import java .util .ArrayList ;
4141import java .util .EnumSet ;
4242import java .util .HashMap ;
43+ import java .util .concurrent .CompletionException ;
4344import java .util .concurrent .ExecutionException ;
4445import java .util .concurrent .Executors ;
4546import java .util .concurrent .ExecutorService ;
4647
4748public class OneModule extends ReactContextBaseJavaModule {
4849 protected static final String NAME = "One" ;
4950 private final ExecutorService executor = Executors .newSingleThreadExecutor ();
51+ private static final boolean THROW_ERRORS = true ;
5052
5153 public OneModule (ReactApplicationContext reactContext ) {
5254 super (reactContext );
@@ -86,30 +88,51 @@ public void sendInteraction(String interactionPath, ReadableMap propertiesMap, f
8688 .interactionPath (new OneInteractionPath (URI .create (interactionPath )))
8789 .properties (properties )
8890 .build ();
91+
8992 executor .submit (() -> {
90- try {
91- OneResponse response ;
92- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ) {
93- response = One .sendInteraction (true , sendInteractionRequest ).join ();
94- } else {
95- response = One .sendInteractionLegacySupport (true , sendInteractionRequest ).join ();
93+ OneResponse response ;
94+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ) {
95+ try {
96+ response = One .sendInteraction (THROW_ERRORS , sendInteractionRequest ).join ();
97+ WritableNativeMap responseMap = responseObjectToReadableMap (response );
98+ notifyResult (promise , responseMap );
99+ } catch (ExecutionException error ) {
100+ notifyProblem (promise , Integer .toString (error .hashCode ()), error .getLocalizedMessage ());
101+ Log .e (NAME , "[Thunderhead] Send Interaction Completion Error: " + error .getCause ());
102+ } catch (OneSDKError error ) {
103+ notifyProblem (promise , Integer .toString (error .getSystemCode ()), error .getLocalizedMessage ());
104+ Log .e (NAME , "[Thunderhead] Send Interaction SDK Error: " + error .getErrorMessage ());
105+ } catch (OneAPIError error ) {
106+ notifyProblem (promise , Integer .toString (error .getHttpStatusCode ()), error .getLocalizedMessage ());
107+ Log .e (NAME , "[Thunderhead] Send Interaction Api Error: " + error .getErrorMessage ());
108+ } catch (CompletionException error ) {
109+ notifyProblem (promise , Integer .toString (error .hashCode ()), error .getLocalizedMessage ());
110+ Log .e (NAME , "[Thunderhead] Send Interaction Completion Error: " + error .getLocalizedMessage ());
111+ } catch (Exception error ) {
112+ notifyProblem (promise , Integer .toString (error .hashCode ()), error .getLocalizedMessage ());
113+ Log .e (NAME , "[Thunderhead] Send Interaction Error: " + error .getLocalizedMessage ());
114+ }
115+ } else {
116+ try {
117+ response = One .sendInteractionLegacySupport (THROW_ERRORS , sendInteractionRequest ).join ();
118+ WritableNativeMap responseMap = responseObjectToReadableMap (response );
119+ notifyResult (promise , responseMap );
120+ } catch (ExecutionException error ) {
121+ notifyProblem (promise , Integer .toString (error .hashCode ()), error .getLocalizedMessage ());
122+ Log .e (NAME , "[Thunderhead] Send Interaction Completion Error: " + error .getCause ());
123+ } catch (OneSDKError error ) {
124+ notifyProblem (promise , Integer .toString (error .getSystemCode ()), error .getLocalizedMessage ());
125+ Log .e (NAME , "[Thunderhead] Send Interaction SDK Error: " + error .getErrorMessage ());
126+ } catch (OneAPIError error ) {
127+ notifyProblem (promise , Integer .toString (error .getHttpStatusCode ()), error .getLocalizedMessage ());
128+ Log .e (NAME , "[Thunderhead] Send Interaction Api Error: " + error .getErrorMessage ());
129+ } catch (Exception error ) {
130+ notifyProblem (promise , Integer .toString (error .hashCode ()), error .getLocalizedMessage ());
131+ Log .e (NAME , "[Thunderhead] Send Interaction Error: " + error .getLocalizedMessage ());
96132 }
97- One .processResponse (response );
98- WritableNativeMap responseMap = responseObjectToReadableMap (response );
99- notifyResult (promise , responseMap );
100- } catch (ExecutionException error ) {
101- notifyProblem (promise , Integer .toString (error .hashCode ()), error .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 (Exception error ) {
110- notifyProblem (promise , Integer .toString (error .hashCode ()), error .getLocalizedMessage ());
111- Log .e (NAME , "[Thunderhead] Send Interaction Error: " + error .getLocalizedMessage ());
112133 }
134+ WritableNativeMap responseMap = responseObjectToReadableMap (response );
135+ notifyResult (promise , responseMap );
113136 });
114137 }
115138
@@ -121,28 +144,47 @@ public void sendProperties(String interactionPath, ReadableMap propertiesMap, fi
121144 .properties (properties )
122145 .build ();
123146 executor .submit (() -> {
124- try {
125- OneResponse response ;
126- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ) {
127- response = One .sendProperties (true , sendPropertiesRequest ).join ();
128- } else {
129- response = One .sendPropertiesLegacySupport (true , sendPropertiesRequest ).join ();
147+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ) {
148+ try {
149+ OneResponse response ;
150+ response = One .sendProperties (THROW_ERRORS , sendPropertiesRequest ).join ();
151+ WritableNativeMap responseMap = responseObjectToReadableMap (response );
152+ notifyResult (promise , responseMap );
153+ } catch (ExecutionException error ) {
154+ notifyProblem (promise , Integer .toString (error .hashCode ()), error .getLocalizedMessage ());
155+ Log .e (NAME , "[Thunderhead] Send Properties Completion Error: " + error .getCause ());
156+ } catch (OneSDKError error ) {
157+ notifyProblem (promise , Integer .toString (error .getSystemCode ()), error .getLocalizedMessage ());
158+ Log .e (NAME , "[Thunderhead] Send Properties SDK Error: " + error .getErrorMessage ());
159+ } catch (OneAPIError error ) {
160+ notifyProblem (promise , Integer .toString (error .getHttpStatusCode ()), error .getLocalizedMessage ());
161+ Log .e (NAME , "[Thunderhead] Send Properties Api Error: " + error .getErrorMessage ());
162+ } catch (CompletionException error ) {
163+ notifyProblem (promise , Integer .toString (error .hashCode ()), error .getLocalizedMessage ());
164+ Log .e (NAME , "[Thunderhead] Send Properties Completion Error: " + error .getLocalizedMessage ());
165+ } catch (Exception error ) {
166+ notifyProblem (promise , Integer .toString (error .hashCode ()), error .getLocalizedMessage ());
167+ Log .e (NAME , "[Thunderhead] Send Interaction Error: " + error .getLocalizedMessage ());
168+ }
169+ } else {
170+ try {
171+ OneResponse response ;
172+ response = One .sendPropertiesLegacySupport (THROW_ERRORS , sendPropertiesRequest ).join ();
173+ WritableNativeMap responseMap = responseObjectToReadableMap (response );
174+ notifyResult (promise , responseMap );
175+ } catch (ExecutionException error ) {
176+ notifyProblem (promise , Integer .toString (error .hashCode ()), error .getLocalizedMessage ());
177+ Log .e (NAME , "[Thunderhead] Send Properties Completion Error: " + error .getCause ());
178+ } catch (OneSDKError error ) {
179+ notifyProblem (promise , Integer .toString (error .getSystemCode ()), error .getLocalizedMessage ());
180+ Log .e (NAME , "[Thunderhead] Send Properties SDK Error: " + error .getErrorMessage ());
181+ } catch (OneAPIError error ) {
182+ notifyProblem (promise , Integer .toString (error .getHttpStatusCode ()), error .getLocalizedMessage ());
183+ Log .e (NAME , "[Thunderhead] Send Properties Api Error: " + error .getErrorMessage ());
184+ } catch (Exception error ) {
185+ notifyProblem (promise , Integer .toString (error .hashCode ()), error .getLocalizedMessage ());
186+ Log .e (NAME , "[Thunderhead] Send Interaction Error: " + error .getLocalizedMessage ());
130187 }
131- One .processResponse (response );
132- WritableNativeMap responseMap = responseObjectToReadableMap (response );
133- notifyResult (promise , responseMap );
134- } catch (ExecutionException error ) {
135- notifyProblem (promise , Integer .toString (error .hashCode ()), error .getLocalizedMessage ());
136- Log .e (NAME , "[Thunderhead] Send Properties Completion Error: " + error .getCause ());
137- } catch (OneSDKError error ) {
138- notifyProblem (promise , Integer .toString (error .getSystemCode ()), error .getLocalizedMessage ());
139- Log .e (NAME , "[Thunderhead] Send Properties SDK Error: " + error .getErrorMessage ());
140- } catch (OneAPIError error ) {
141- notifyProblem (promise , Integer .toString (error .getHttpStatusCode ()), error .getLocalizedMessage ());
142- Log .e (NAME , "[Thunderhead] Send Properties Api Error: " + error .getErrorMessage ());
143- } catch (Exception error ) {
144- notifyProblem (promise , Integer .toString (error .hashCode ()), error .getLocalizedMessage ());
145- Log .e (NAME , "[Thunderhead] Send Interaction Error: " + error .getLocalizedMessage ());
146188 }
147189 });
148190 }
@@ -154,27 +196,45 @@ public void sendResponseCode(String interactionPath, String responseCode, final
154196 .responseCode (new OneResponseCode (responseCode ))
155197 .interactionPath (new OneInteractionPath (URI .create (interactionPath )))
156198 .build ();
157-
158- try {
159- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ) {
160- One .sendResponseCode (true , responseCodeRequest ).join ();
161- } else {
162- One .sendResponseCodeLegacySupport (true , responseCodeRequest ).join ();
199+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ) {
200+ try {
201+ One .sendResponseCode (THROW_ERRORS , responseCodeRequest ).join ();
202+ notifyResult (promise , null );
203+ } catch (ExecutionException error ) {
204+ notifyProblem (promise , Integer .toString (error .hashCode ()), error .getLocalizedMessage ());
205+ Log .e (NAME , "[Thunderhead] Send Response Code Completion Error: " + error .getCause ());
206+ } catch (OneSDKError error ) {
207+ notifyProblem (promise , Integer .toString (error .getSystemCode ()), error .getLocalizedMessage ());
208+ Log .e (NAME , "[Thunderhead] Send Response Code SDK Error: " + error .getErrorMessage ());
209+ } catch (OneAPIError error ) {
210+ notifyProblem (promise , Integer .toString (error .getHttpStatusCode ()), error .getLocalizedMessage ());
211+ Log .e (NAME , "[Thunderhead] Send Response Code Api Error: " + error .getErrorMessage ());
212+ } catch (CompletionException error ) {
213+ notifyProblem (promise , Integer .toString (error .hashCode ()), error .getLocalizedMessage ());
214+ Log .e (NAME , "[Thunderhead] Send Properties Completion Error: " + error .getLocalizedMessage ());
215+ } catch (Exception error ) {
216+ notifyProblem (promise , Integer .toString (error .hashCode ()), error .getLocalizedMessage ());
217+ Log .e (NAME , "[Thunderhead] Send Interaction Error: " + error .getLocalizedMessage ());
218+ }
219+ } else {
220+ try {
221+ One .sendResponseCodeLegacySupport (THROW_ERRORS , responseCodeRequest ).join ();
222+ notifyResult (promise , null );
223+ } catch (ExecutionException error ) {
224+ notifyProblem (promise , Integer .toString (error .hashCode ()), error .getLocalizedMessage ());
225+ Log .e (NAME , "[Thunderhead] Send Response Code Completion Error: " + error .getCause ());
226+ } catch (OneSDKError error ) {
227+ notifyProblem (promise , Integer .toString (error .getSystemCode ()), error .getLocalizedMessage ());
228+ Log .e (NAME , "[Thunderhead] Send Response Code SDK Error: " + error .getErrorMessage ());
229+ } catch (OneAPIError error ) {
230+ notifyProblem (promise , Integer .toString (error .getHttpStatusCode ()), error .getLocalizedMessage ());
231+ Log .e (NAME , "[Thunderhead] Send Response Code Api Error: " + error .getErrorMessage ());
232+ } catch (Exception error ) {
233+ notifyProblem (promise , Integer .toString (error .hashCode ()), error .getLocalizedMessage ());
234+ Log .e (NAME , "[Thunderhead] Send Interaction Error: " + error .getLocalizedMessage ());
163235 }
164- notifyResult (promise , null );
165- } catch (ExecutionException error ) {
166- notifyProblem (promise , Integer .toString (error .hashCode ()), error .getLocalizedMessage ());
167- Log .e (NAME , "[Thunderhead] Send Response Code Completion Error: " + error .getCause ());
168- } catch (OneSDKError error ) {
169- notifyProblem (promise , Integer .toString (error .getSystemCode ()), error .getLocalizedMessage ());
170- Log .e (NAME , "[Thunderhead] Send Response Code SDK Error: " + error .getErrorMessage ());
171- } catch (OneAPIError error ) {
172- notifyProblem (promise , Integer .toString (error .getHttpStatusCode ()), error .getLocalizedMessage ());
173- Log .e (NAME , "[Thunderhead] Send Response Code Api Error: " + error .getErrorMessage ());
174- } catch (Exception error ) {
175- notifyProblem (promise , Integer .toString (error .hashCode ()), error .getLocalizedMessage ());
176- Log .e (NAME , "[Thunderhead] Send Interaction Error: " + error .getLocalizedMessage ());
177236 }
237+
178238 });
179239 }
180240
0 commit comments