Skip to content

Commit 28a981d

Browse files
rlopezapplaudoRafael Lopez
and
Rafael Lopez
authored
fix(bridge): fix duplicated analytics client improving errors (#162)
Co-authored-by: Rafael Lopez <[email protected]>
1 parent 43c4fa1 commit 28a981d

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

packages/core/android/src/main/java/com/segment/analytics/reactnative/core/RNAnalyticsModule.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,13 @@ class RNAnalyticsModule(context: ReactApplicationContext): ReactContextBaseJavaM
112112
return promise.resolve(null)
113113
}
114114
else {
115-
return promise.reject("E_SEGMENT_RECONFIGURED", "Duplicate Analytics client")
115+
if (BuildConfig.DEBUG) {
116+
return pomise.resolve(this)
117+
}
118+
else {
119+
return promise.reject("E_SEGMENT_RECONFIGURED", "Segment Analytics Client was allocated multiple times, please check your environment.")
120+
}
121+
116122
}
117123
}
118124

packages/core/ios/RNAnalytics/RNAnalytics.m

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ +(void)initialize {
4646
return resolver(nil);
4747
}
4848
else {
49-
return rejecter(@"E_SEGMENT_RECONFIGURED", @"Duplicate Analytics client", nil);
49+
#if DEBUG
50+
return resolver(self);
51+
#else
52+
return rejecter(@"E_SEGMENT_RECONFIGURED", @"Segment Analytics Client was allocated multiple times, please check your environment.", nil);
53+
#endif
5054
}
5155
}
5256

@@ -67,7 +71,7 @@ +(void)initialize {
6771
@try {
6872
[SEGAnalytics setupWithConfiguration:config];
6973
}
70-
@catch(NSException* error) {
74+
@catch(NSError* error) {
7175
return rejecter(@"E_SEGMENT_ERROR", @"Unexpected native Analtyics error", error);
7276
}
7377

@@ -85,7 +89,7 @@ +(void)initialize {
8589
}
8690

8791
singletonJsonConfig = json;
88-
resolver(nil);
92+
return resolver(nil);
8993
}
9094

9195
- (NSDictionary*)withContextAndIntegrations :(NSDictionary*)context :(NSDictionary*)integrations {

0 commit comments

Comments
 (0)