Bluesky app fork with some witchin' additions 💫

Filter errors that get sent to Sentry (#5247)

authored by hailey.at and committed by

GitHub 58036ffb b1ca2503

+30 -15
+7 -7
__tests__/lib/errors.test.ts
··· 9 9 ] 10 10 const outputs = [true, false, false, true] 11 11 12 - it('correctly distinguishes network errors', () => { 13 - for (let i = 0; i < inputs.length; i++) { 14 - const input = inputs[i] 15 - const result = isNetworkError(input) 16 - expect(result).toEqual(outputs[i]) 17 - } 18 - }) 12 + for (let i = 0; i < inputs.length; i++) { 13 + const input = inputs[i] 14 + const output = outputs[i] 15 + it(`correctly distinguishes network errors for ${input}`, () => { 16 + expect(isNetworkError(input)).toEqual(output) 17 + }) 18 + } 19 19 })
+13 -5
src/lib/strings/errors.ts
··· 20 20 return str 21 21 } 22 22 23 + const NETWORK_ERRORS = [ 24 + 'Abort', 25 + 'Network request failed', 26 + 'Failed to fetch', 27 + 'Load failed', 28 + ] 29 + 23 30 export function isNetworkError(e: unknown) { 24 31 const str = String(e) 25 - return ( 26 - str.includes('Abort') || 27 - str.includes('Network request failed') || 28 - str.includes('Failed to fetch') 29 - ) 32 + for (const err of NETWORK_ERRORS) { 33 + if (str.includes(err)) { 34 + return true 35 + } 36 + } 37 + return false 30 38 }
+8 -2
src/logger/index.ts
··· 1 1 import format from 'date-fns/format' 2 2 import {nanoid} from 'nanoid/non-secure' 3 3 4 + import {DebugContext} from '#/logger/debugContext' 5 + import {add} from '#/logger/logDump' 4 6 import {Sentry} from '#/logger/sentry' 7 + import {isNetworkError} from 'lib/strings/errors' 5 8 import * as env from '#/env' 6 - import {DebugContext} from '#/logger/debugContext' 7 - import {add} from '#/logger/logDump' 8 9 9 10 export enum LogLevel { 10 11 Debug = 'debug', ··· 159 160 level: severity, 160 161 timestamp: timestamp / 1000, // Sentry expects seconds 161 162 }) 163 + 164 + // We don't want to send any network errors to sentry 165 + if (isNetworkError(message)) { 166 + return 167 + } 162 168 163 169 /** 164 170 * Send all higher levels with `captureMessage`, with appropriate severity
+2 -1
src/view/com/util/UserAvatar.tsx
··· 327 327 328 328 onSelectNewAvatar(croppedImage) 329 329 } catch (e: any) { 330 - if (!String(e).includes('Canceled')) { 330 + // Don't log errors for cancelling selection to sentry on ios or android 331 + if (!String(e).toLowerCase().includes('cancel')) { 331 332 logger.error('Failed to crop banner', {error: e}) 332 333 } 333 334 }