Filter errors that get sent to Sentry (#5247)
This commit is contained in:
@@ -9,11 +9,11 @@ describe('isNetworkError', () => {
|
|||||||
]
|
]
|
||||||
const outputs = [true, false, false, true]
|
const outputs = [true, false, false, true]
|
||||||
|
|
||||||
it('correctly distinguishes network errors', () => {
|
for (let i = 0; i < inputs.length; i++) {
|
||||||
for (let i = 0; i < inputs.length; i++) {
|
const input = inputs[i]
|
||||||
const input = inputs[i]
|
const output = outputs[i]
|
||||||
const result = isNetworkError(input)
|
it(`correctly distinguishes network errors for ${input}`, () => {
|
||||||
expect(result).toEqual(outputs[i])
|
expect(isNetworkError(input)).toEqual(output)
|
||||||
}
|
})
|
||||||
})
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -20,11 +20,19 @@ export function cleanError(str: any): string {
|
|||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const NETWORK_ERRORS = [
|
||||||
|
'Abort',
|
||||||
|
'Network request failed',
|
||||||
|
'Failed to fetch',
|
||||||
|
'Load failed',
|
||||||
|
]
|
||||||
|
|
||||||
export function isNetworkError(e: unknown) {
|
export function isNetworkError(e: unknown) {
|
||||||
const str = String(e)
|
const str = String(e)
|
||||||
return (
|
for (const err of NETWORK_ERRORS) {
|
||||||
str.includes('Abort') ||
|
if (str.includes(err)) {
|
||||||
str.includes('Network request failed') ||
|
return true
|
||||||
str.includes('Failed to fetch')
|
}
|
||||||
)
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-2
@@ -1,10 +1,11 @@
|
|||||||
import format from 'date-fns/format'
|
import format from 'date-fns/format'
|
||||||
import {nanoid} from 'nanoid/non-secure'
|
import {nanoid} from 'nanoid/non-secure'
|
||||||
|
|
||||||
import {Sentry} from '#/logger/sentry'
|
|
||||||
import * as env from '#/env'
|
|
||||||
import {DebugContext} from '#/logger/debugContext'
|
import {DebugContext} from '#/logger/debugContext'
|
||||||
import {add} from '#/logger/logDump'
|
import {add} from '#/logger/logDump'
|
||||||
|
import {Sentry} from '#/logger/sentry'
|
||||||
|
import {isNetworkError} from 'lib/strings/errors'
|
||||||
|
import * as env from '#/env'
|
||||||
|
|
||||||
export enum LogLevel {
|
export enum LogLevel {
|
||||||
Debug = 'debug',
|
Debug = 'debug',
|
||||||
@@ -160,6 +161,11 @@ export const sentryTransport: Transport = (
|
|||||||
timestamp: timestamp / 1000, // Sentry expects seconds
|
timestamp: timestamp / 1000, // Sentry expects seconds
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// We don't want to send any network errors to sentry
|
||||||
|
if (isNetworkError(message)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send all higher levels with `captureMessage`, with appropriate severity
|
* Send all higher levels with `captureMessage`, with appropriate severity
|
||||||
* level
|
* level
|
||||||
|
|||||||
@@ -327,7 +327,8 @@ let EditableUserAvatar = ({
|
|||||||
|
|
||||||
onSelectNewAvatar(croppedImage)
|
onSelectNewAvatar(croppedImage)
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
if (!String(e).includes('Canceled')) {
|
// Don't log errors for cancelling selection to sentry on ios or android
|
||||||
|
if (!String(e).toLowerCase().includes('cancel')) {
|
||||||
logger.error('Failed to crop banner', {error: e})
|
logger.error('Failed to crop banner', {error: e})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user