Skip to content

Commit c44e2b6

Browse files
committed
fix to warn only known error patterns
1 parent 4aa4ad7 commit c44e2b6

File tree

2 files changed

+39
-18
lines changed

2 files changed

+39
-18
lines changed

src/utils/errorMessage.ts

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,32 @@ import { capitalizeFirstLetter } from 'utils/string'
66
const matchPatterns = (patterns: string[], error: string) =>
77
patterns.some(pattern => error.toLowerCase().includes(pattern.toLowerCase()))
88

9+
export const knownPatterns = {
10+
insufficient_erc20_balance: 'Insufficient ERC20 balance to pay gas fee',
11+
router_expired: 'An error occurred. Refresh the page and try again.',
12+
already_pending: 'Pending request(s), please approve it in your wallet.',
13+
mintotalamountout: 'An error occurred. Try refreshing the price rate or increase max slippage.',
14+
from_address_mismatch: 'The requested account and/or method has not been authorized by the user.',
15+
insufficient_funds: 'Your current balance falls short of covering the required gas fee.',
16+
swap_failed:
17+
'An error occurred. Refresh the page and try again. If the issue still persists, it might be an issue with your RPC node settings in Metamask.',
18+
underlying_network_changed: 'Your chain is mismatched, please make sure your wallet is switch to the expected chain.',
19+
user_rejected: 'User rejected the transaction.',
20+
insufficient: 'An error occurred. Please try increasing max slippage.',
21+
permit: 'An error occurred. Invalid Permit Signature.',
22+
burn_amount_exceeds_balance:
23+
'Insufficient fee rewards amount, try to remove your liquidity without claiming fees for now and you can try to claim it later.',
24+
object_object: 'Something went wrong. Please try again.',
25+
}
26+
927
function parseKnownPattern(text: string): string | undefined {
1028
const error = text?.toLowerCase?.() || ''
1129

12-
if (matchPatterns(['insufficient erc20 balance'], error)) return t`Insufficient ERC20 balance to pay gas fee`
30+
if (matchPatterns(['insufficient erc20 balance'], error)) return knownPatterns.insufficient_erc20_balance
1331

14-
if (!error || error.includes('router: expired')) return t`An error occurred. Refresh the page and try again.`
32+
if (!error || error.includes('router: expired')) return knownPatterns.router_expired
1533

16-
if (matchPatterns(['already pending'], error)) return t`Pending request(s), please approve it in your wallet.`
34+
if (matchPatterns(['already pending'], error)) return knownPatterns.already_pending
1735

1836
if (
1937
matchPatterns(
@@ -28,41 +46,38 @@ function parseKnownPattern(text: string): string | undefined {
2846
error,
2947
)
3048
)
31-
return t`An error occurred. Try refreshing the price rate or increase max slippage.`
49+
return knownPatterns.mintotalamountout
3250

3351
if (
3452
matchPatterns(
3553
['The requested account and/or method has not been authorized by the user', 'From address mismatch'],
3654
error,
3755
)
3856
)
39-
return t`The requested account and/or method has not been authorized by the user.`
57+
return knownPatterns.from_address_mismatch
4058

4159
if (
4260
matchPatterns(
4361
['insufficient funds for intrinsic transaction cost', 'OutOfFund', 'insufficient balance for transfer'],
4462
error,
4563
)
4664
)
47-
return t`Your current balance falls short of covering the required gas fee.`
65+
return knownPatterns.insufficient_funds
4866

49-
if (matchPatterns(['header not found', 'swap failed'], error))
50-
return t`An error occurred. Refresh the page and try again. If the issue still persists, it might be an issue with your RPC node settings in Metamask.`
67+
if (matchPatterns(['header not found', 'swap failed'], error)) return knownPatterns.swap_failed
5168

52-
if (matchPatterns(['underlying network changed'], error))
53-
return t`Your chain is mismatched, please make sure your wallet is switch to the expected chain.`
69+
if (matchPatterns(['underlying network changed'], error)) return knownPatterns.underlying_network_changed
5470

55-
if (didUserReject(error)) return t`User rejected the transaction.`
71+
if (didUserReject(error)) return knownPatterns.user_rejected
5672

5773
// classic/elastic remove liquidity error
58-
if (matchPatterns(['insufficient'], error)) return t`An error occurred. Please try increasing max slippage.`
74+
if (matchPatterns(['insufficient'], error)) return knownPatterns.insufficient
5975

60-
if (matchPatterns(['permit'], error)) return t`An error occurred. Invalid Permit Signature.`
76+
if (matchPatterns(['permit'], error)) return knownPatterns.permit
6177

62-
if (matchPatterns(['burn amount exceeds balance'], error))
63-
return t`Insufficient fee rewards amount, try to remove your liquidity without claiming fees for now and you can try to claim it later.`
78+
if (matchPatterns(['burn amount exceeds balance'], error)) return knownPatterns.burn_amount_exceeds_balance
6479

65-
if (error === '[object Object]') return t`Something went wrong. Please try again.`
80+
if (error === '[object Object]') return knownPatterns.object_object
6681

6782
return undefined
6883
}

src/utils/sentry.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Deferrable } from 'ethers/lib/utils'
44

55
import { didUserReject } from 'constants/connectors/utils'
66

7-
import { friendlyError } from './errorMessage'
7+
import { friendlyError, knownPatterns } from './errorMessage'
88

99
export enum ErrorName {
1010
LimitOrderError = 'LimitOrderError',
@@ -34,8 +34,14 @@ export function captureSwapError(error: TransactionError) {
3434
? 'returnAmountIsNotEnough'
3535
: 'other'
3636

37+
const level = Object.keys(knownPatterns)
38+
.map(key => knownPatterns[key])
39+
.includes(friendlyErrorResult)
40+
? 'warning'
41+
: 'error'
42+
3743
captureException(e, {
38-
level: 'warning',
44+
level,
3945
extra: { rawData: error.rawData },
4046
tags: {
4147
type: tag,

0 commit comments

Comments
 (0)