From 78ab3a2f903ab9b3188650b68852d0845807b687 Mon Sep 17 00:00:00 2001 From: "Hung-Han (Henry) Chen" Date: Thu, 8 Jul 2021 10:24:28 +0300 Subject: [PATCH] Add type for Sentry event Signed-off-by: Hung-Han (Henry) Chen --- package.json | 1 + src/common/sentry.ts | 5 ++++- yarn.lock | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 5b6d00a824..d1daf823ac 100644 --- a/package.json +++ b/package.json @@ -255,6 +255,7 @@ "@material-ui/lab": "^4.0.0-alpha.57", "@pmmmwh/react-refresh-webpack-plugin": "^0.4.3", "@sentry/react": "^6.8.0", + "@sentry/types": "^6.8.0", "@testing-library/jest-dom": "^5.13.0", "@testing-library/react": "^11.2.6", "@types/byline": "^4.2.32", diff --git a/src/common/sentry.ts b/src/common/sentry.ts index 140da033f6..513954e89c 100644 --- a/src/common/sentry.ts +++ b/src/common/sentry.ts @@ -20,6 +20,7 @@ */ import { CaptureConsole, Dedupe, Offline } from "@sentry/integrations"; +import type { Event as SentryEvent } from "@sentry/types"; import { sentryDsn, sentryDsnIsValid, isProduction } from "./vars"; import { UserStore } from "./user-store"; import logger from "../main/logger"; @@ -82,7 +83,7 @@ export const SentryInit = () => { try { Sentry.init({ - beforeSend(event: unknown) { + beforeSend(event: SentryEvent) { const allowErrorReporting = UserStore.getInstance().allowErrorReporting; if (allowErrorReporting) return event; @@ -90,6 +91,8 @@ export const SentryInit = () => { logger.info(`🔒 [SENTRY-BEFORE-SEND-HOOK]: allowErrorReporting: ${allowErrorReporting}. Sentry event is caught but not sent to server.`); logger.info(event); + // if return null, the event won't be sent + // ref https://github.com/getsentry/sentry-javascript/issues/2039 return null; }, dsn: sentryDsn, diff --git a/yarn.lock b/yarn.lock index e28b3ed07d..1602d70c9c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1088,7 +1088,7 @@ resolved "https://registry.yarnpkg.com/@sentry/types/-/types-6.7.1.tgz#c8263e1886df5e815570c4668eb40a1cfaa1c88b" integrity sha512-9AO7HKoip2MBMNQJEd6+AKtjj2+q9Ze4ooWUdEvdOVSt5drg7BGpK221/p9JEOyJAZwEPEXdcMd3VAIMiOb4MA== -"@sentry/types@6.8.0": +"@sentry/types@6.8.0", "@sentry/types@^6.8.0": version "6.8.0" resolved "https://registry.yarnpkg.com/@sentry/types/-/types-6.8.0.tgz#97fd531a0ed1e75e65b4a24b26509fb7c15eb7b8" integrity sha512-PbSxqlh6Fd5thNU5f8EVYBVvX+G7XdPA+ThNb2QvSK8yv3rIf0McHTyF6sIebgJ38OYN7ZFK7vvhC/RgSAfYTA==