Skip to content

Commit

Permalink
feat: sentry catch init error
Browse files Browse the repository at this point in the history
  • Loading branch information
Venipa committed Jan 21, 2025
1 parent da89f65 commit 4c0a0d9
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/main/utils/sentry.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
import * as Sentry from "@sentry/electron/main";
import logger from "@shared/utils/Logger";
let enabledReporting = true;
const sentryLog = logger.child("Sentry");
export const setSentryEnabled = (enable: boolean) => {
if (enabledReporting !== enable) enabledReporting = enable;
if (!enable) logger.child("Sentry").warn("Sentry has been disabled");
else logger.child("Sentry").warn("Sentry has been enabled");
if (!enable) sentryLog.warn("Sentry has been disabled");
else sentryLog.warn("Sentry has been enabled");
};

if (import.meta.env.VITE_SENTRY_DSN) {
Sentry &&
!Sentry.isInitialized &&
if (import.meta.env.VITE_SENTRY_DSN && Sentry && !Sentry.isInitialized) {
try {
Sentry.init({
dsn: import.meta.env.VITE_SENTRY_DSN,
enabled: true,
onFatalError(error) {
if (enabledReporting) sentryLog.error(error);
},
beforeSend: (ev) => {
if (!enabledReporting) return null;
return ev;
},
});
logger.child("Sentry").info("Sentry has been initialized");
} else logger.child("Sentry").warn("Sentry is not enabled");
} catch {
sentryLog.warn("Sentry has failed to initialize, server may not be reachable.");
} finally {
sentryLog.info("Sentry has been initialized");
}
} else if (!Sentry || !Sentry.isInitialized) sentryLog.warn("Sentry is not enabled");
export { Sentry };

0 comments on commit 4c0a0d9

Please sign in to comment.