feat: resolve errors more cautious

This commit is contained in:
EnixCoda 2020-01-08 23:42:30 +08:00
parent bf2bd4d4de
commit 94a9317e13
No known key found for this signature in database
GPG key ID: 0C1A07377913A1DD

View file

@ -5,13 +5,36 @@ import { IN_PRODUCTION_MODE, VERSION } from 'env'
const PUBLIC_KEY = 'd22ec5c9cc874539a51c78388c12e3b0'
const PROJECT_ID = '1406497'
const errorSet = new Set<string>([
'inThisSearch is null', // weird bug in Firefox
'The quota has been exceeded.', // caused by other addons in Firefox
'NetworkError when attempting to fetch resource.', // network fail in Firefox
'Failed to fetch', // network fail in Chrome
])
const sentryOptions: Sentry.BrowserOptions = {
dsn: `https://${PUBLIC_KEY}@sentry.io/${PROJECT_ID}`,
release: VERSION,
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
integrations: ints => ints.filter(({ name }) => name !== 'TryCatch'),
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
}
return event
},
beforeBreadcrumb(breadcrumb, hint) {
if (breadcrumb.category === 'ui.click') {
const ariaLabel = hint?.event?.target?.ariaLabel
if (ariaLabel) {
breadcrumb.message = ariaLabel
}
}
return breadcrumb
},
}
Sentry.init(sentryOptions)