Skip to content

Commit fd88340

Browse files
committed
Store event if exception before sending
1 parent 500ca15 commit fd88340

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

ios/RNSentry.m

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,16 @@ - (void)setReleaseVersionDist:(SentryEvent *)event {
206206
[self injectReactNativeFrames:event];
207207
[self setReleaseVersionDist:event];
208208
};
209+
client.shouldSendEvent = ^BOOL(SentryEvent * _Nonnull event) {
210+
// We don't want to send an event after startup that came from a NSException of react native
211+
// Because we sent it already before the app crashed.
212+
if (nil != event.exceptions.firstObject.type &&
213+
[event.exceptions.firstObject.type rangeOfString:@"RCTFatalException"].location != NSNotFound) {
214+
NSLog(@"RCTFatalException");
215+
return NO;
216+
}
217+
return YES;
218+
};
209219
[SentryClient setSharedClient:client];
210220
[SentryClient.sharedClient startCrashHandlerWithError:&error];
211221
if (error) {
@@ -346,8 +356,16 @@ - (void)swizzleCallNativeModule:(Class)class {
346356
[frames addObject:[stacktrace objectAtIndex:i]];
347357
}
348358
[self addExceptionToEvent:sentryEvent type:exception[@"type"] value:exception[@"value"] frames:frames];
359+
#if DEBUG
360+
// We want to send the exception instead of storing it because in debug
361+
// the app does not crash it will restart
362+
[SentryClient.sharedClient sendEvent:sentryEvent withCompletionHandler:NULL];
363+
#else
364+
[SentryClient.sharedClient storeEvent:sentryEvent];
365+
#endif
366+
} else {
367+
[SentryClient.sharedClient sendEvent:sentryEvent withCompletionHandler:NULL];
349368
}
350-
[SentryClient.sharedClient sendEvent:sentryEvent withCompletionHandler:NULL];
351369
[RNSentryEventEmitter emitStoredEvent];
352370
}
353371

0 commit comments

Comments
 (0)