Skip to content
This repository has been archived by the owner on Sep 14, 2020. It is now read-only.

fix: ignore empty api key from react native #237

Merged
merged 7 commits into from
May 24, 2018
25 changes: 24 additions & 1 deletion cocoa/BugsnagReactNative.m
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ + (void)startWithConfiguration:(BugsnagConfiguration *)config {
RCT_EXPORT_MODULE()

RCT_EXPORT_METHOD(notify:(NSDictionary *)options) {
if (![Bugsnag bugsnagStarted]) {
return;
}

NSString *const EXCEPTION_TYPE = @"browserjs";
NSException *exception = [NSException
exceptionWithName:[RCTConvert NSString:options[@"errorClass"]]
Expand Down Expand Up @@ -181,21 +185,33 @@ + (void)startWithConfiguration:(BugsnagConfiguration *)config {
}

RCT_EXPORT_METHOD(setUser:(NSDictionary *)userInfo) {
if (![Bugsnag bugsnagStarted]) {
return;
}
NSString *identifier = userInfo[@"id"] ? [RCTConvert NSString:userInfo[@"id"]] : nil;
NSString *name = userInfo[@"name"] ? [RCTConvert NSString:userInfo[@"name"]] : nil;
NSString *email = userInfo[@"email"] ? [RCTConvert NSString:userInfo[@"email"]] : nil;
[[Bugsnag configuration] setUser:identifier withName:name andEmail:email];
}

RCT_EXPORT_METHOD(startSession) {
if (![Bugsnag bugsnagStarted]) {
return;
}
[Bugsnag startSession];
}

RCT_EXPORT_METHOD(clearUser) {
if (![Bugsnag bugsnagStarted]) {
return;
}
[[Bugsnag configuration] setUser:nil withName:nil andEmail:nil];
}

RCT_EXPORT_METHOD(leaveBreadcrumb:(NSDictionary *)options) {
if (![Bugsnag bugsnagStarted]) {
return;
}
[Bugsnag leaveBreadcrumbWithBlock:^(BugsnagBreadcrumb *crumb) {
crumb.name = [RCTConvert NSString:options[@"name"]];
crumb.type = BreadcrumbTypeFromString([RCTConvert NSString:options[@"type"]]);
Expand All @@ -215,7 +231,11 @@ + (void)startWithConfiguration:(BugsnagConfiguration *)config {
NSString *appVersion = [RCTConvert NSString:options[@"appVersion"]];
NSString *codeBundleId = [RCTConvert NSString:options[@"codeBundleId"]];
BugsnagConfiguration* config = [Bugsnag bugsnagStarted] ? [Bugsnag configuration] : [BugsnagConfiguration new];
config.apiKey = apiKey;

if (apiKey.length > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like the right solution on the bugsnag-react-native side

config.apiKey = apiKey;
}

config.releaseStage = releaseStage;
config.notifyReleaseStages = notifyReleaseStages;
config.autoNotify = [RCTConvert BOOL:options[@"autoNotify"]];
Expand Down Expand Up @@ -254,6 +274,9 @@ + (void)startWithConfiguration:(BugsnagConfiguration *)config {
}

- (void)setNotifierDetails:(NSString *)packageVersion {
if (![Bugsnag bugsnagStarted]) {
return;
}
id notifier = [Bugsnag notifier];
NSDictionary *details = [notifier valueForKey:@"details"];
NSString *version;
Expand Down
2 changes: 1 addition & 1 deletion cocoa/vendor/bugsnag-cocoa/Source/BugsnagSessionTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ - (void)startNewSession:(NSDate *)date
- (void)trackSession {
[self.sessionStore write:self.currentSession];
self.trackedFirstSession = YES;

if (self.callback) {
self.callback(self.currentSession);
}
Expand Down