Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
62675e88
Commit
62675e88
authored
Jan 02, 2025
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
setup filters for Rollbar events
parent
878e8950
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
110 additions
and
8 deletions
+110
-8
throwOnAbsentParamError.ts
lib/errors/throwOnAbsentParamError.ts
+3
-1
useGetCsrfToken.tsx
lib/hooks/useGetCsrfToken.tsx
+7
-7
index.tsx
lib/rollbar/index.tsx
+42
-0
utils.ts
lib/rollbar/utils.ts
+58
-0
No files found.
lib/errors/throwOnAbsentParamError.ts
View file @
62675e88
export
const
ABSENT_PARAM_ERROR_MESSAGE
=
'
Required param not provided
'
;
export
default
function
throwOnAbsentParamError
(
param
:
unknown
)
{
export
default
function
throwOnAbsentParamError
(
param
:
unknown
)
{
if
(
!
param
)
{
if
(
!
param
)
{
throw
new
Error
(
'
Required param not provided
'
,
{
cause
:
{
status
:
404
}
});
throw
new
Error
(
ABSENT_PARAM_ERROR_MESSAGE
,
{
cause
:
{
status
:
404
}
});
}
}
}
}
lib/hooks/useGetCsrfToken.tsx
View file @
62675e88
...
@@ -5,11 +5,9 @@ import isNeedProxy from 'lib/api/isNeedProxy';
...
@@ -5,11 +5,9 @@ import isNeedProxy from 'lib/api/isNeedProxy';
import
{
getResourceKey
}
from
'
lib/api/useApiQuery
'
;
import
{
getResourceKey
}
from
'
lib/api/useApiQuery
'
;
import
*
as
cookies
from
'
lib/cookies
'
;
import
*
as
cookies
from
'
lib/cookies
'
;
import
useFetch
from
'
lib/hooks/useFetch
'
;
import
useFetch
from
'
lib/hooks/useFetch
'
;
import
{
useRollbar
}
from
'
lib/rollbar
'
;
export
default
function
useGetCsrfToken
()
{
export
default
function
useGetCsrfToken
()
{
const
nodeApiFetch
=
useFetch
();
const
nodeApiFetch
=
useFetch
();
const
rollbar
=
useRollbar
();
return
useQuery
({
return
useQuery
({
queryKey
:
getResourceKey
(
'
csrf
'
),
queryKey
:
getResourceKey
(
'
csrf
'
),
...
@@ -20,11 +18,13 @@ export default function useGetCsrfToken() {
...
@@ -20,11 +18,13 @@ export default function useGetCsrfToken() {
const
csrfFromHeader
=
apiResponse
.
headers
.
get
(
'
x-bs-account-csrf
'
);
const
csrfFromHeader
=
apiResponse
.
headers
.
get
(
'
x-bs-account-csrf
'
);
if
(
!
csrfFromHeader
)
{
if
(
!
csrfFromHeader
)
{
rollbar
?.
warn
(
'
Client fetch failed
'
,
{
// I am not sure should we log this error or not
resource
:
'
csrf
'
,
// so I commented it out for now
status_code
:
500
,
// rollbar?.warn('Client fetch failed', {
status_text
:
'
Unable to obtain csrf token from header
'
,
// resource: 'csrf',
});
// status_code: 500,
// status_text: 'Unable to obtain csrf token from header',
// });
return
;
return
;
}
}
...
...
lib/rollbar/index.tsx
View file @
62675e88
...
@@ -3,6 +3,10 @@ import type React from 'react';
...
@@ -3,6 +3,10 @@ import type React from 'react';
import
type
{
Configuration
}
from
'
rollbar
'
;
import
type
{
Configuration
}
from
'
rollbar
'
;
import
config
from
'
configs/app
'
;
import
config
from
'
configs/app
'
;
import
{
ABSENT_PARAM_ERROR_MESSAGE
}
from
'
lib/errors/throwOnAbsentParamError
'
;
import
{
RESOURCE_LOAD_ERROR_MESSAGE
}
from
'
lib/errors/throwOnResourceLoadError
'
;
import
{
isBot
,
isHeadlessBrowser
,
isNextJsChunkError
,
getRequestInfo
}
from
'
./utils
'
;
const
feature
=
config
.
features
.
rollbar
;
const
feature
=
config
.
features
.
rollbar
;
...
@@ -20,4 +24,42 @@ export const clientConfig: Configuration | undefined = feature.isEnabled ? {
...
@@ -20,4 +24,42 @@ export const clientConfig: Configuration | undefined = feature.isEnabled ? {
code_version
:
feature
.
codeVersion
,
code_version
:
feature
.
codeVersion
,
app_instance
:
feature
.
instance
,
app_instance
:
feature
.
instance
,
},
},
checkIgnore
(
isUncaught
,
args
,
item
)
{
if
(
isBot
(
window
.
navigator
.
userAgent
))
{
return
true
;
}
if
(
isHeadlessBrowser
(
window
.
navigator
.
userAgent
))
{
return
true
;
}
if
(
isNextJsChunkError
(
getRequestInfo
(
item
)?.
url
))
{
return
true
;
}
return
false
;
},
hostSafeList
:
[
config
.
app
.
host
].
filter
(
Boolean
),
ignoredMessages
:
[
// these are React errors - "NotFoundError: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node."
// they could be caused by browser extensions
// one of the examples - https://github.com/facebook/react/issues/11538
// we can ignore them for now
'
NotFoundError
'
,
// these are errors that we throw on when make a call to the API
RESOURCE_LOAD_ERROR_MESSAGE
,
ABSENT_PARAM_ERROR_MESSAGE
,
// Filter out network-related errors that are usually not actionable
'
Network Error
'
,
'
Failed to fetch
'
,
// Filter out CORS errors from third-party extensions
'
cross-origin
'
,
// Filter out client-side navigation cancellations
'
cancelled navigation
'
,
],
maxItems
:
10
,
// Max items per page load
}
:
undefined
;
}
:
undefined
;
lib/rollbar/utils.ts
0 → 100644
View file @
62675e88
import
type
{
Dictionary
}
from
'
rollbar
'
;
export
function
isBot
(
userAgent
:
string
|
undefined
)
{
if
(
!
userAgent
)
return
false
;
const
botPatterns
=
[
'
Googlebot
'
,
// Google
'
Baiduspider
'
,
// Baidu
'
bingbot
'
,
// Bing
'
YandexBot
'
,
// Yandex
'
DuckDuckBot
'
,
// DuckDuckGo
'
Slurp
'
,
// Yahoo
'
Applebot
'
,
// Apple
'
facebookexternalhit
'
,
// Facebook
'
Twitterbot
'
,
// Twitter
'
rogerbot
'
,
// Moz
'
Alexa
'
,
// Alexa
'
AhrefsBot
'
,
// Ahrefs
'
SemrushBot
'
,
// Semrush
'
spider
'
,
// Generic spiders
'
crawler
'
,
// Generic crawlers
];
return
botPatterns
.
some
(
pattern
=>
userAgent
.
toLowerCase
().
includes
(
pattern
.
toLowerCase
()),
);
}
export
function
isHeadlessBrowser
(
userAgent
:
string
|
undefined
)
{
if
(
!
userAgent
)
return
false
;
if
(
userAgent
.
includes
(
'
headless
'
)
||
userAgent
.
includes
(
'
phantomjs
'
)
||
userAgent
.
includes
(
'
selenium
'
)
||
userAgent
.
includes
(
'
puppeteer
'
)
)
{
return
true
;
}
}
export
function
isNextJsChunkError
(
url
:
unknown
)
{
if
(
typeof
url
!==
'
string
'
)
return
false
;
return
url
.
includes
(
'
/_next/
'
);
}
export
function
getRequestInfo
(
item
:
Dictionary
):
{
url
:
string
}
|
undefined
{
if
(
!
item
.
request
||
item
.
request
===
null
||
typeof
item
.
request
!==
'
object
'
||
!
(
'
url
'
in
item
.
request
)
||
typeof
item
.
request
.
url
!==
'
string
'
)
{
return
undefined
;
}
return
{
url
:
item
.
request
.
url
};
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment