FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
uniswap_interface_sc/apps/web/src/tracing/errors.ts at main · stringcode86/uniswap_interface_sc · GitHub
stringcode86
uniswap_interface_sc
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
uniswap_interface_sc
/
apps
/
web
/
src
/
tracing
/
errors.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
174 lines (152 loc) · 6.67 KB
Breadcrumbs
uniswap_interface_sc
/
apps
/
web
/
src
/
tracing
/
errors.ts
Copy path
File metadata and controls
174 lines (152 loc) · 6.67 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import
{
ClientOptions
,
ErrorEvent
,
EventHint
}
from
'@sentry/types'
import
{
ProviderRpcError
}
from
'@web3-react/types'
import
{
wagmiConfig
}
from
'components/Web3Provider/wagmiConfig'
import
{
didUserReject
}
from
'utils/swapErrorToUserReadableMessage'
import
{
getAccount
}
from
'wagmi/actions'
// `responseStatus` is only currently supported on certain browsers.
// see: https://caniuse.com/mdn-api_performanceresourcetiming_responsestatus
declare
global
{
interface
PerformanceEntry
{
responseStatus
?:
number
}
}
/**
* Filters known (ignorable) errors out before sending them to Sentry. Also, adds tags to the event.
* Intended as a {
@link
ClientOptions.beforeSend} callback. Returning null filters the error from Sentry.
*/
export
const
beforeSend
:
Required
<
ClientOptions
>
[
'beforeSend'
]
=
(
event
:
ErrorEvent
,
hint
:
EventHint
)
=>
{
if
(
shouldRejectError
(
hint
.
originalException
)
)
{
return
null
}
const
exception
=
event
.
exception
?.
values
?.
[
0
]
if
(
exception
?.
mechanism
&&
exception
.
mechanism
.
synthetic
&&
!
exception
.
mechanism
.
handled
)
{
// ProviderRpcErrors occur frequently through 3P providers, so it's good to disambiguate them.
// This allows us to see which errors are actually frequent, vs which ones are extension-specific.
if
(
isProviderRpcError
(
hint
.
originalException
)
)
{
event
.
exception
?.
values
?.
push
(
{
type
:
'ProviderRpcError'
,
value
:
`
${
hint
.
originalException
.
code
}
:
${
hint
.
originalException
.
message
}
`
,
}
)
}
}
updateRequestUrl
(
event
)
updateConnection
(
event
)
return
event
}
type
ErrorLike
=
Partial
<
Error
>
&
Required
<
Pick
<
Error
,
'message'
>
>
function
isErrorLike
(
error
:
unknown
)
:
error
is
ErrorLike
{
return
error
instanceof
Object
&&
'message'
in
error
&&
typeof
(
error
as
Partial
<
ErrorLike
>
)
?.
message
===
'string'
}
/** Identifies ethers request errors (as thrown by {
@type
import(@ethersproject/web).fetchJson}). */
function
isEthersRequestErrorLike
(
error
:
ErrorLike
)
:
error
is
ErrorLike
&
{
requestBody
:
string
}
{
return
'requestBody'
in
error
&&
typeof
(
error
as
Record
<
'requestBody'
,
unknown
>
)
.
requestBody
===
'string'
}
// Since the interface currently uses HashRouter, URLs will have a # before the path.
// This leads to issues when we send the URL into Sentry, as the path gets parsed as a "fragment".
// Instead, this logic removes the # part of the URL.
// It also removes trailing slashes, as they are not needed.
// See https://romain-clement.net/articles/sentry-url-fragments/#url-fragments
function
updateRequestUrl
(
event
:
ErrorEvent
)
{
if
(
event
.
request
?.
url
)
{
event
.
request
.
url
=
event
.
request
.
url
.
replace
(
'/#'
,
''
)
if
(
event
.
request
.
url
.
endsWith
(
'/'
)
)
{
event
.
request
.
url
=
event
.
request
.
url
.
slice
(
0
,
-
1
)
}
}
}
function
updateConnection
(
event
:
ErrorEvent
)
{
const
{
status
,
address
,
connector
}
=
getAccount
(
wagmiConfig
)
event
.
extra
=
{
...
event
.
extra
,
connection
:
{
type
:
connector
?.
type
,
name
:
connector
?.
name
,
rdns
:
connector
?.
id
,
address
,
status
,
}
,
}
event
.
tags
=
{
...
event
.
tags
,
connectionStatus
:
status
,
connection
:
connector
?.
id
??
connector
?.
name
??
connector
?.
type
,
}
}
// TODO(WEB-2400): Refactor to use a config instead of returning true for each condition.
function
shouldRejectError
(
error
:
EventHint
[
'originalException'
]
)
{
// Some libraries throw ErrorLike objects ({ code, message, stack }) instead of true Errors.
if
(
isErrorLike
(
error
)
)
{
if
(
isEthersRequestErrorLike
(
error
)
)
{
const
method
=
JSON
.
parse
(
error
.
requestBody
)
.
method
// ethers aggressively polls for block number, and it sometimes fails (whether spuriously or through rate-limiting).
// If block number polling, it should not be considered an exception.
if
(
method
===
'eth_blockNumber'
)
{
return
true
}
}
// If the error is based on a user rejecting, it should not be considered an exception.
// TODO(WEB-2398): we should catch these errors and handle them gracefully instead.
if
(
didUserReject
(
error
)
)
{
return
true
}
// If the error is a network change, it should not be considered an exception.
if
(
error
.
message
.
match
(
/
u
n
d
e
r
l
y
i
n
g
n
e
t
w
o
r
k
c
h
a
n
g
e
d
/
)
)
{
return
true
}
// This is caused by HTML being returned for a chunk from Cloudflare.
// Usually, it's the result of a 499 exception right before it, which should be handled.
// Therefore, this can be ignored.
if
(
error
.
message
.
match
(
/
U
n
e
x
p
e
c
t
e
d
t
o
k
e
n
'
<
'
/
)
)
{
return
true
}
// Content security policy 'unsafe-eval' errors can be filtered out because there are expected failures.
// For example, if a user runs an eval statement in console this error would still get thrown.
// TODO(WEB-2348): We should extend this to filter out any type of CSP error.
if
(
error
.
message
.
match
(
/
'
u
n
s
a
f
e
-
e
v
a
l
'
.
*
c
o
n
t
e
n
t
s
e
c
u
r
i
t
y
p
o
l
i
c
y
/
i
)
)
{
return
true
}
if
(
error
.
message
.
match
(
/
B
l
o
c
k
e
d
a
f
r
a
m
e
w
i
t
h
o
r
i
g
i
n
"
.
*
"
f
r
o
m
a
c
c
e
s
s
i
n
g
a
c
r
o
s
s
-
o
r
i
g
i
n
f
r
a
m
e
.
/
)
)
{
return
true
}
if
(
error
.
message
.
match
(
/
N
o
t
A
l
l
o
w
e
d
E
r
r
o
r
:
W
r
i
t
e
p
e
r
m
i
s
s
i
o
n
d
e
n
i
e
d
.
/
)
)
{
return
true
}
// WebAssembly compilation fails because we do not allow 'unsafe-eval' in our CSP.
// Any thrown errors are due to 3P extensions/applications, so we do not need to handle them.
if
(
error
.
message
.
match
(
/
W
e
b
A
s
s
e
m
b
l
y
.
i
n
s
t
a
n
t
i
a
t
e
\(
\)
:
W
a
s
m
c
o
d
e
g
e
n
e
r
a
t
i
o
n
d
i
s
a
l
l
o
w
e
d
b
y
e
m
b
e
d
d
e
r
/
)
)
{
return
true
}
// Filters out errors caused by checking for meta tags that may not exist.
if
(
error
.
message
.
match
(
/
n
u
l
l
i
s
n
o
t
a
n
o
b
j
e
c
t
\(
e
v
a
l
u
a
t
i
n
g
'
d
o
c
u
m
e
n
t
\.
q
u
e
r
y
S
e
l
e
c
t
o
r
\(
'
m
e
t
a
\[
[
^
\]
]
+
\]
'
\)
\.
c
o
n
t
e
n
t
'
\)
/
)
)
{
return
true
}
if
(
'stack'
in
error
&&
typeof
error
.
stack
===
'string'
)
{
// Errors coming from a browser extension can be ignored. These errors are usually caused by extensions injecting
// scripts into the page, which we cannot control.
if
(
error
.
stack
.
match
(
/
-
e
x
t
e
n
s
i
o
n
:
\/
\/
/
i
)
)
{
return
true
}
// Errors coming from OneKey (a desktop wallet) can be ignored for now.
// These errors are either application-specific, or they will be thrown separately outside of OneKey.
if
(
error
.
stack
.
match
(
/
O
n
e
K
e
y
/
i
)
)
{
return
true
}
}
// These are caused by user navigation away from the page before a request has finished.
if
(
error
instanceof
DOMException
&&
error
?.
name
===
'AbortError'
)
{
return
true
}
}
return
false
}
function
isProviderRpcError
(
error
:
unknown
)
:
error
is
ProviderRpcError
{
return
(
error
instanceof
Object
&&
'code'
in
error
&&
typeof
(
error
as
Partial
<
ProviderRpcError
>
)
?.
code
===
'number'
&&
'message'
in
error
&&
typeof
(
error
as
Partial
<
ProviderRpcError
>
)
?.
message
===
'string'
)
}
Back
|
FazBrowse Home
|
New Git URL