Skip to content

Commit 7ff02b8

Browse files
authored
Silence defined error codes (baserow#5012)
1 parent 8efd87b commit 7ff02b8

4 files changed

Lines changed: 32 additions & 2 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"type": "refactor",
3+
"message": "Silence defined error codes in Sentry",
4+
"issue_origin": "github",
5+
"issue_number": 5011,
6+
"domain": "core",
7+
"bullet_points": [],
8+
"created_at": "2026-03-19"
9+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// API error codes to silence in Sentry, keyed by HTTP status code.
2+
// These are handled by the application (e.g. forceLogoff) and are not bugs.
3+
export const SILENCED_API_ERRORS = {
4+
401: ['ERROR_INVALID_ACCESS_TOKEN', 'ERROR_INVALID_REFRESH_TOKEN'],
5+
}

web-frontend/sentry.client.config.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useRuntimeConfig, useAppConfig, useRouter } from '#imports'
22
import { makeFakeTransport } from './modules/core/utils/sentryFakeTransport'
3+
import { SILENCED_API_ERRORS } from './modules/core/utils/sentryErrors'
34
import * as Sentry from '@sentry/nuxt'
45

56
const config = useRuntimeConfig()
@@ -30,14 +31,21 @@ if (dsn && dsn !== '') {
3031
...(isDev ? { transport: makeFakeTransport } : {}),
3132
beforeSend(event, hint) {
3233
const err = hint?.originalException
33-
if (err?.fatal === false || err?.response?.status === 401) return null
34+
if (err?.fatal === false) return null
3435

3536
// Filter out axios errors without a response like
3637
// network error, timeout, aborted, cancelled requests
3738
if (err?.name === 'AxiosError' && !err?.response) {
3839
return null
3940
}
4041

42+
// Filter known API errors that are handled by the application (e.g. forceLogoff).
43+
const status = err?.response?.status || err?.statusCode
44+
const errorCode = err?.response?.data?.error || err?.data?.error
45+
if (SILENCED_API_ERRORS[status]?.includes(errorCode)) {
46+
return null
47+
}
48+
4149
if (isDev) {
4250
console.error('[Sentry captured error]', `${err}`)
4351
return null

web-frontend/sentry.server.config.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useRuntimeConfig } from '#imports'
22
import * as Sentry from '@sentry/nuxt'
33
import { makeFakeTransport } from './modules/core/utils/sentryFakeTransport'
4+
import { SILENCED_API_ERRORS } from './modules/core/utils/sentryErrors'
45

56
const config = useRuntimeConfig()
67
const dsn =
@@ -18,7 +19,14 @@ if (dsn && dsn !== '') {
1819
...(isDev ? { transport: makeFakeTransport } : {}),
1920
beforeSend(event, hint) {
2021
const err = hint?.originalException
21-
if (err?.fatal === false || err?.response?.status === 401) return null
22+
if (err?.fatal === false) return null
23+
24+
// Filter known API errors that are handled by the application (e.g. forceLogoff).
25+
const status = err?.response?.status || err?.statusCode
26+
const errorCode = err?.response?.data?.error || err?.data?.error
27+
if (SILENCED_API_ERRORS[status]?.includes(errorCode)) {
28+
return null
29+
}
2230
if (isDev) {
2331
console.error('[Sentry captured error]', err)
2432
return null

0 commit comments

Comments
 (0)