Commit fd1aded5 authored by Vignesh Mohankumar's avatar Vignesh Mohankumar Committed by GitHub

fix: remove trailing slash from request url (#6542)

* fix: remove trailing slash from request url

* moves cast

* {}
parent 27ad7cbd
...@@ -10,6 +10,41 @@ Object.defineProperty(window.performance, 'getEntriesByType', { ...@@ -10,6 +10,41 @@ Object.defineProperty(window.performance, 'getEntriesByType', {
describe('beforeSend', () => { describe('beforeSend', () => {
const ERROR = {} as ErrorEvent const ERROR = {} as ErrorEvent
describe('updateRequestUrl', () => {
test('should remove "/#" from the request URL', () => {
const event = {
request: {
url: 'https://app.uniswap.org/#/example',
},
} as ErrorEvent
beforeSend(event, {})
expect(event.request?.url).toBe('https://app.uniswap.org/example')
})
test('should remove trailing slash from the request URL', () => {
const event = {
request: {
url: 'https://app.uniswap.org/example/',
},
} as ErrorEvent
beforeSend(event, {})
expect(event.request?.url).toBe('https://app.uniswap.org/example')
})
test('should not modify the request URL if no changes are required', () => {
const event = {
request: {
url: 'https://app.uniswap.org/example',
},
} as ErrorEvent
beforeSend(event, {})
expect(event.request?.url).toBe('https://app.uniswap.org/example')
})
})
describe('chunkResponseStatus', () => { describe('chunkResponseStatus', () => {
afterEach(() => { afterEach(() => {
jest.restoreAllMocks() jest.restoreAllMocks()
......
...@@ -31,10 +31,14 @@ function isEthersRequestError(error: Error): error is Error & { requestBody: str ...@@ -31,10 +31,14 @@ function isEthersRequestError(error: Error): error is Error & { requestBody: str
// Since the interface currently uses HashRouter, URLs will have a # before the path. // 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". // 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. // 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 // See https://romain-clement.net/articles/sentry-url-fragments/#url-fragments
function updateRequestUrl(event: ErrorEvent) { function updateRequestUrl(event: ErrorEvent) {
if (event.request?.url) { if (event.request?.url) {
event.request.url = event.request.url.replace('/#', '') event.request.url = event.request.url.replace('/#', '')
if (event.request.url.endsWith('/')) {
event.request.url = event.request.url.slice(0, -1)
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment