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

chore: remove chunkResponseStatus tag (#6586)

* chore: remove chunkResponseStatus tag

* lint
parent 835c62ac
import { ErrorEvent, Event } from '@sentry/types' import { ErrorEvent } from '@sentry/types'
import { beforeSend } from './errors' import { beforeSend } from './errors'
...@@ -45,58 +45,6 @@ describe('beforeSend', () => { ...@@ -45,58 +45,6 @@ describe('beforeSend', () => {
}) })
}) })
describe('chunkResponseStatus', () => {
afterEach(() => {
jest.restoreAllMocks()
})
it('handles when matching JS file not found', () => {
jest.spyOn(window.performance, 'getEntriesByType').mockReturnValue([])
const originalException = new Error(
'Loading chunk 20 failed. (error: https://app.uniswap.org/static/js/20.d55382e0.chunk.js)'
)
expect((beforeSend(ERROR, { originalException }) as Event).tags).toBeUndefined()
})
it('handles when matching CSS file not found', () => {
jest.spyOn(window.performance, 'getEntriesByType').mockReturnValue([])
const originalException = new Error(
'Loading chunk 20 failed. (error: https://app.uniswap.org/static/js/20.d55382e0.chunk.js)'
)
expect((beforeSend(ERROR, { originalException }) as Event).tags).toBeUndefined()
})
it('handles when performance is undefined', () => {
window.performance = undefined as any
const originalException = new Error('Loading CSS chunk 12 failed. (./static/css/12.d5b3cfe3.chunk.css)')
expect((beforeSend(ERROR, { originalException }) as Event).tags).toBeUndefined()
})
it('adds status for a matching JS file', () => {
jest.spyOn(window.performance, 'getEntriesByType').mockReturnValue([
{
name: 'https://app.uniswap.org/static/js/20.d55382e0.chunk.js',
responseStatus: 499,
} as PerformanceEntry,
])
const originalException = new Error(
'Loading chunk 20 failed. (error: https://app.uniswap.org/static/js/20.d55382e0.chunk.js)'
)
expect((beforeSend(ERROR, { originalException }) as Event).tags?.chunkResponseStatus).toBe(499)
})
it('adds status for a matching CSS file', () => {
jest.spyOn(window.performance, 'getEntriesByType').mockReturnValue([
{
name: 'https://app.uniswap.org/static/css/12.d5b3cfe3.chunk.css',
responseStatus: 200,
} as PerformanceEntry,
])
const originalException = new Error('Loading CSS chunk 12 failed. (./static/css/12.d5b3cfe3.chunk.css)')
expect((beforeSend(ERROR, { originalException }) as Event).tags?.chunkResponseStatus).toBe(200)
})
})
it('propagates an error', () => { it('propagates an error', () => {
expect(beforeSend(ERROR, {})).toBe(ERROR) expect(beforeSend(ERROR, {})).toBe(ERROR)
}) })
......
...@@ -18,7 +18,6 @@ export const beforeSend: Required<ClientOptions>['beforeSend'] = (event: ErrorEv ...@@ -18,7 +18,6 @@ export const beforeSend: Required<ClientOptions>['beforeSend'] = (event: ErrorEv
} }
updateRequestUrl(event) updateRequestUrl(event)
addChunkResponseStatusTag(event, hint)
return event return event
} }
...@@ -42,39 +41,6 @@ function updateRequestUrl(event: ErrorEvent) { ...@@ -42,39 +41,6 @@ function updateRequestUrl(event: ErrorEvent) {
} }
} }
// If a request fails due to a chunk error, this looks for that asset in the performance entries.
// If found, it adds a tag to the event with the response status of the chunk request.
function addChunkResponseStatusTag(event: ErrorEvent, hint: EventHint) {
const error = hint.originalException
if (error instanceof Error) {
let asset: string | undefined
if (error.message.match(/Loading chunk \d+ failed\. \(([a-zA-Z]+): .+\.chunk\.js\)/)) {
asset = error.message.match(/https?:\/\/.+?\.chunk\.js/)?.[0]
}
if (error.message.match(/Loading CSS chunk \d+ failed\. \(.+\.chunk\.css\)/)) {
const relativePath = error.message.match(/\/static\/css\/.*\.chunk\.css/)?.[0]
asset = `${window.origin}${relativePath}`
}
if (asset) {
const status = getChunkResponseStatus(asset)
if (status) {
if (!event.tags) {
event.tags = {}
}
event.tags.chunkResponseStatus = status
}
}
}
}
function getChunkResponseStatus(asset?: string): number | undefined {
const entries = [...(performance?.getEntriesByType('resource') ?? [])]
const resource = entries?.find(({ name }) => name === asset)
return resource?.responseStatus
}
function shouldRejectError(error: EventHint['originalException']) { function shouldRejectError(error: EventHint['originalException']) {
if (error instanceof Error) { if (error instanceof Error) {
// ethers aggressively polls for block number, and it sometimes fails (whether spuriously or through rate-limiting). // ethers aggressively polls for block number, and it sometimes fails (whether spuriously or through rate-limiting).
......
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