Don't send empty reports now for real

This commit is contained in:
crschnick
2023-10-21 21:11:14 +00:00
parent 45e501f4fd
commit ca3acc2d1d
@@ -35,7 +35,6 @@ public class SentryErrorHandler implements ErrorHandler {
options.setDsn(AppProperties.get().getSentryUrl());
options.setEnableUncaughtExceptionHandler(false);
options.setAttachServerName(false);
// options.setDebug(true);
options.setRelease(AppProperties.get().getVersion());
options.setEnableShutdownHook(false);
options.setProguardUuid(AppProperties.get().getBuildUuid().toString());
@@ -49,7 +48,7 @@ public class SentryErrorHandler implements ErrorHandler {
init = true;
}
var id = createReport(ee);
var id = captureEvent(ee);
if (id == null) {
return;
}
@@ -57,8 +56,7 @@ public class SentryErrorHandler implements ErrorHandler {
var email = ee.getEmail();
var hasEmail = email != null && !email.isBlank();
var text = ee.getUserReport();
var hasText = text != null && !text.isBlank();
if (hasText || hasEmail) {
if (hasUserReport(ee)) {
var fb = new UserFeedback(id);
if (hasEmail) {
fb.setEmail(email);
@@ -69,6 +67,14 @@ public class SentryErrorHandler implements ErrorHandler {
Sentry.flush(3000);
}
private static boolean hasUserReport(ErrorEvent ee) {
var email = ee.getEmail();
var hasEmail = email != null && !email.isBlank();
var text = ee.getUserReport();
var hasText = text != null && !text.isBlank();
return hasEmail || hasText;
}
private static Throwable adjustCopy(Throwable throwable, boolean clear) {
if (throwable == null) {
return null;
@@ -102,7 +108,11 @@ public class SentryErrorHandler implements ErrorHandler {
}
}
private static SentryId createReport(ErrorEvent ee) {
private static SentryId captureEvent(ErrorEvent ee) {
if (!hasUserReport(ee) && "User Report".equals(ee.getDescription())) {
return null;
}
if (ee.getThrowable() != null) {
var adjusted = adjustCopy(ee.getThrowable(), !ee.isShouldSendDiagnostics());
return Sentry.captureException(adjusted, sc -> fillScope(ee, sc));