Skip to content

Commit b8d3c24

Browse files
authored
Remove NSUnderlyingErrorKey when it is an NSNull object (#135)
* Remove `NSUnderlyingErrorKey` when it is an `NSNull` object - NSErrors that are return from Intercom can have a value of `NSNull`. ReactNative is unable to handle this so we strip them out to avoid crashing the app. * Update IntercomModule.m
1 parent a473e74 commit b8d3c24

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

example/ios/Podfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ PODS:
7474
- fmt (6.2.1)
7575
- glog (0.3.5)
7676
- Intercom (16.0.1)
77-
- intercom-react-native (5.3.1):
77+
- intercom-react-native (6.0.0):
7878
- Intercom (~> 16.0.1)
7979
- React-Core
8080
- libevent (2.1.12)
@@ -519,7 +519,7 @@ EXTERNAL SOURCES:
519519
SPEC CHECKSUMS:
520520
boost: a7c83b31436843459a1961bfd74b96033dc77234
521521
CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99
522-
DoubleConversion: 5189b271737e1565bdce30deb4a08d647e3f5f54
522+
DoubleConversion: 831926d9b8bf8166fd87886c4abab286c2422662
523523
FBLazyVector: bc76253beb7463b688aa6af913b822ed631de31a
524524
FBReactNativeSpec: 85d34420d92cb178897de05e3aba90e7a8568162
525525
Flipper: 26fc4b7382499f1281eb8cb921e5c3ad6de91fe0
@@ -532,9 +532,9 @@ SPEC CHECKSUMS:
532532
Flipper-RSocket: d9d9ade67cbecf6ac10730304bf5607266dd2541
533533
FlipperKit: cbdee19bdd4e7f05472a66ce290f1b729ba3cb86
534534
fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9
535-
glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b
535+
glog: 5337263514dd6f09803962437687240c5dc39aa4
536536
Intercom: 62fe4d94519fba99f17df3f7a0c62dc7dbcb7b02
537-
intercom-react-native: bfa2ea64fba2b38f3b0c48afe020b05ac0007cb3
537+
intercom-react-native: 7bf5734cca0629303b514e188e60d7d87c17338c
538538
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
539539
OpenSSL-Universal: ebc357f1e6bc71fa463ccb2fe676756aff50e88c
540540
RCT-Folly: 0080d0a6ebf2577475bda044aa59e2ca1f909cda

ios/IntercomModule.m

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ - (NSData *)dataFromHexString:(NSString *)string {
100100
[Intercom loginUnidentifiedUserWithSuccess:^{
101101
successCallback(@(YES));
102102
} failure:^(NSError * _Nonnull error) {
103-
failureCallback(error);
103+
failureCallback([self removeNullUnderlyingError:error]);
104104
}];
105105
};
106106

@@ -119,7 +119,7 @@ - (NSData *)dataFromHexString:(NSString *)string {
119119
[Intercom loginUserWithUserAttributes:attributes success:^{
120120
successCallback(@(YES));
121121
} failure:^(NSError * _Nonnull error) {
122-
failureCallback(error);
122+
failureCallback([self removeNullUnderlyingError:error]);
123123
}];
124124
}
125125

@@ -135,7 +135,7 @@ - (NSData *)dataFromHexString:(NSString *)string {
135135
[Intercom updateUser:userAttributes success:^{
136136
resolve(@(YES));
137137
} failure:^(NSError * _Nonnull error) {
138-
failureCallback(error);
138+
failureCallback([self removeNullUnderlyingError:error]);
139139
}];
140140
};
141141

@@ -360,4 +360,20 @@ - (NSError *)exceptionToError:(NSException *)exception :(NSString *)code :(NSStr
360360

361361
return [[NSError alloc] initWithDomain:domain code:[code integerValue] userInfo:info];
362362
};
363+
364+
365+
/// Remove `NSUnderlyingErrorKey` from the `userInfo` if its value is of type `NSNull`
366+
///
367+
/// NSErrors that are return from Intercom can have a value of `NSNull`. ReactNative is unable to handle this so we
368+
/// strip them out to avoid crashing the app.
369+
/// - Parameter error: the `NSError` object.
370+
- (NSError *)removeNullUnderlyingError:(NSError *)error {
371+
NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
372+
NSError *underlyingError = [error.userInfo objectForKey:NSUnderlyingErrorKey];
373+
[userInfo addEntriesFromDictionary:error.userInfo];
374+
if([underlyingError isKindOfClass:[NSNull class]]) {
375+
[userInfo removeObjectForKey:NSUnderlyingErrorKey];
376+
}
377+
return [[NSError alloc] initWithDomain:error.domain code:error.code userInfo:userInfo];
378+
};
363379
@end

0 commit comments

Comments
 (0)