@@ -77,6 +77,16 @@ -(void)stopObserving {
7777 return events;
7878}
7979
80+ - (NSArray <NSString *> *)processNSError : (NSError *)error {
81+ if (error.userInfo [@" error" ]) {
82+ return @[error.userInfo[@" error" ]];
83+ } else if (error.userInfo [@" returned" ]) {
84+ return @[error.userInfo[@" returned" ]];
85+ } else {
86+ return @[error.localizedDescription];
87+ }
88+ }
89+
8090
8191#pragma mark Send Event Methods
8292
@@ -275,15 +285,15 @@ + (void)sendEventWithName:(NSString *)name withBody:(NSDictionary *)body {
275285 [OneSignal setEmail: email withEmailAuthHashToken: authHash withSuccess: ^{
276286 callback (@[]);
277287 } withFailure: ^(NSError *error) {
278- callback (@[error.userInfo[ @" error " ] ?: error.localizedDescription ]);
288+ callback ([ self processNSError: error]);
279289 }];
280290}
281291
282292RCT_EXPORT_METHOD (logoutEmail:(RCTResponseSenderBlock)callback) {
283293 [OneSignal logoutEmailWithSuccess: ^{
284294 callback (@[]);
285295 } withFailure: ^(NSError *error) {
286- callback (@[error.userInfo[ @" error " ] ?: error.localizedDescription ]);
296+ callback ([ self processNSError: error]);
287297 }];
288298}
289299
@@ -292,15 +302,15 @@ + (void)sendEventWithName:(NSString *)name withBody:(NSDictionary *)body {
292302 [OneSignal setSMSNumber: smsNumber withSMSAuthHashToken: authHash withSuccess: ^(NSDictionary *results) {
293303 callback (@[results]);
294304 } withFailure: ^(NSError *error) {
295- callback (@[error.userInfo[ @" error " ] ?: error.localizedDescription ]);
305+ callback ([ self processNSError: error]);
296306 }];
297307}
298308
299309RCT_EXPORT_METHOD (logoutSMSNumber:(RCTResponseSenderBlock)callback) {
300310 [OneSignal logoutSMSNumberWithSuccess: ^(NSDictionary *results) {
301311 callback (@[results]);
302312 } withFailure: ^(NSError *error) {
303- callback (@[error.userInfo[ @" error " ] ?: error.localizedDescription ]);
313+ callback ([ self processNSError: error]);
304314 }];
305315}
306316
@@ -372,7 +382,7 @@ + (void)sendEventWithName:(NSString *)name withBody:(NSDictionary *)body {
372382 successCallback (@[success]);
373383 } onFailure: ^(NSError *error) {
374384 [OneSignal onesignalLog: ONE_S_LL_ERROR message: [NSString stringWithFormat: @" Notification Send Failure with Error: %@ " , error]];
375- failureCallback (@[error.userInfo[ @" error " ] ?: error.localizedDescription ]);
385+ failureCallback ([ self processNSError: error]);
376386 }];
377387}
378388
@@ -393,7 +403,7 @@ + (void)sendEventWithName:(NSString *)name withBody:(NSDictionary *)body {
393403 } withFailure: ^(NSError *error) {
394404 [OneSignal onesignalLog: ONE_S_LL_VERBOSE message: [NSString stringWithFormat: @" OneSignal setExternalUserId error: %@ " , error]];
395405 if (callback) {
396- callback (@[error.userInfo[ @" error " ] ?: error.localizedDescription ]);
406+ callback ([ self processNSError: error]);
397407 }
398408 }];
399409}
@@ -410,7 +420,7 @@ + (void)sendEventWithName:(NSString *)name withBody:(NSDictionary *)body {
410420 }
411421 } withFailure: ^(NSError *error) {
412422 [OneSignal onesignalLog: ONE_S_LL_VERBOSE message: [NSString stringWithFormat: @" OneSignal removeExternalUserId error: %@ " , error]];
413- callback (@[error.userInfo[ @" error " ] ?: error.localizedDescription ]);
423+ callback ([ self processNSError: error]);
414424 }];
415425}
416426
0 commit comments