fix: retrieve error message properly and protect error peak

This commit is contained in:
EnixCoda 2020-01-11 00:53:18 +08:00
parent 21f2999061
commit d0411be620
No known key found for this signature in database
GPG key ID: 0C1A07377913A1DD

View file

@ -5,6 +5,9 @@ import { IN_PRODUCTION_MODE, VERSION } from 'env'
const PUBLIC_KEY = 'd22ec5c9cc874539a51c78388c12e3b0'
const PROJECT_ID = '1406497'
const MAX_REPORT_COUNT = 10 // protect for error leaking
let countReportedError = 0
const errorSet = new Set<string>([
'inThisSearch is null', // weird bug in Firefox
'The quota has been exceeded.', // caused by other addons in Firefox
@ -18,13 +21,19 @@ const sentryOptions: Sentry.BrowserOptions = {
environment: IN_PRODUCTION_MODE ? 'production' : 'development',
// Not safe to activate all integrations in non-Chrome environments where Gitako may not run in top context
// https://docs.sentry.io/platforms/javascript/#sdk-integrations
defaultIntegrations: false,
integrations: integrations => integrations.filter(({ name }) => name !== 'TryCatch'),
beforeSend(event) {
if (event.message) {
if (errorSet.has(event.message)) return null
errorSet.add(event.message) // prevent reporting duplicated error
const message = event.exception?.values?.[0].value || event.message
if (message) {
if (errorSet.has(message)) return null
errorSet.add(message) // prevent reporting duplicated error
}
return event
if (countReportedError < MAX_REPORT_COUNT) {
++countReportedError
return event
}
return null
},
beforeBreadcrumb(breadcrumb, hint) {
if (breadcrumb.category === 'ui.click') {