import { redactPrivateLinks } from '@baserow/modules/core/utils/templatePrivateLink' // API error codes to silence in Sentry, keyed by HTTP status code. // These are handled by the application (e.g. forceLogoff) and are not bugs. export const SILENCED_API_ERRORS = { 401: ['ERROR_INVALID_ACCESS_TOKEN', 'ERROR_INVALID_REFRESH_TOKEN'], } // Browser-extension RPC artifact that rejects a promise when its internal // object registry can't resolve an id. Not a Baserow error. export const SILENCED_ERROR_PATTERNS = [ /Object Not Found Matching Id:\d+, MethodName:\w+, ParamCount:\d+/, ] const isSilenced = (err) => { if (err?.fatal === false) { return true } if (err?.fatal === true && err?.data?.report === false) { return true } if (err?.name === 'AxiosError' && !err?.response) { return true } const status = err?.response?.status || err?.statusCode const errorCode = err?.response?.data?.error || err?.data?.error return Boolean(SILENCED_API_ERRORS[status]?.includes(errorCode)) } /** * The Sentry `beforeSend` of Baserow: drops the errors the app handles, like * network failures and expired tokens, and redacts private links. */ export const filterAndRedactEvent = (event, hint) => isSilenced(hint?.originalException) ? null : redactPrivateLinks(event)