Skip to content

Commit

Permalink
refactor Sentry error
Browse files Browse the repository at this point in the history
  • Loading branch information
tienkane committed Oct 24, 2024
1 parent 285feb1 commit 4aa4ad7
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/hooks/useEthersProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function clientToProvider(client?: Client<Transport, Chain>, chainId?: number) {
}
const { chain, transport } = client

const ensAddress = chain.contracts?.ensRegistry?.address
const ensAddress = chain?.contracts?.ensRegistry?.address
const network = chain
? {
chainId: chain.id,
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useLogin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const useLogin = (autoLogin = false) => {
} catch (error) {
const e = new Error('createProfile Error', { cause: error })
e.name = 'createProfile Error'
captureException(e, { extra: { walletAddress, account } })
captureException(e, { extra: { walletAddress, account }, level: 'warning' })
setProfile({ profile: undefined, isAnonymous, account })
}
},
Expand Down
19 changes: 17 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,25 @@ if (ENV_LEVEL > ENV_TYPE.LOCAL) {
environment: 'production',
ignoreErrors: ['AbortError'],
integrations: [Sentry.browserTracingIntegration(), Sentry.replayIntegration()],
tracesSampleRate: 0.1,
tracesSampleRate: 1.0,
normalizeDepth: 5,
replaysSessionSampleRate: 0.1,
replaysSessionSampleRate: 1.0,
replaysOnErrorSampleRate: 1.0,
beforeSend(event, hint) {
const error = hint?.originalException as Error
const { name, message } = error
if (
(name === 'TypeError' && message === 'Load failed') || // Almost come from mobile safari fetch API issues
(name === 'ChunkLoadError' && message.includes('Failed to fetch')) ||
(name === 'Error' && message === 'Java object is gone') ||
(name === 'UnhandledRejection' && message === 'Non-Error promise rejection captured with value: null') ||
(name === '<unknown>' && message.includes('Non-Error promise rejection captured with value')) || // this always happens when a some external library throws an error
(name === '<unknown>' && message.includes('Object captured as promise rejection with keys')) // this always happens when a some external library throws an error
)
return null

return event
},
})
Sentry.setTag('request_id', sentryRequestId)
Sentry.setTag('version', TAG)
Expand Down
2 changes: 1 addition & 1 deletion src/state/transactions/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const initialState: TransactionState = {}
const clearOldTransactions = (transactions: GroupedTxsByHash | undefined): GroupedTxsByHash | undefined => {
if (!transactions) return undefined
const chainTxs = Object.values(transactions ?? {}).filter(Boolean) as TransactionDetails[][]
chainTxs.sort((a, b) => a[0].addedTime - b[0].addedTime)
chainTxs.sort((a, b) => (a[0]?.addedTime || 0) - (b[0]?.addedTime || 0))
const slicedChainTxs = chainTxs.slice(-10).filter(tx => tx[0].addedTime > Date.now() - 7 * 24 * 60 * 60 * 1000)
const result = slicedChainTxs.reduce((acc, cur) => ({ ...acc, [cur[0].hash]: cur }), {}) as GroupedTxsByHash
return result
Expand Down
2 changes: 1 addition & 1 deletion src/utils/sentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function captureSwapError(error: TransactionError) {
: 'other'

captureException(e, {
level: 'fatal',
level: 'warning',
extra: { rawData: error.rawData },
tags: {
type: tag,
Expand Down

0 comments on commit 4aa4ad7

Please sign in to comment.