mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-27 12:56:01 +01:00
92971d3c87
* Update eslint-plugin-import version * Convert JS files to use ESM * Update ESLint rules to check imports * Fix test:unit:global command env * Cleanup mock-dev script
39 lines
973 B
JavaScript
39 lines
973 B
JavaScript
export default setupFetchDebugging
|
|
|
|
//
|
|
// This is a utility to help resolve cases where `window.fetch` throws a
|
|
// `TypeError: Failed to Fetch` without any stack or context for the request
|
|
// https://github.com/getsentry/sentry-javascript/pull/1293
|
|
//
|
|
|
|
function setupFetchDebugging () {
|
|
if (!global.fetch) {
|
|
return
|
|
}
|
|
const originalFetch = global.fetch
|
|
|
|
global.fetch = wrappedFetch
|
|
|
|
async function wrappedFetch (...args) {
|
|
const initialStack = getCurrentStack()
|
|
try {
|
|
return await originalFetch.call(window, ...args)
|
|
} catch (err) {
|
|
if (!err.stack) {
|
|
console.warn('FetchDebugger - fetch encountered an Error without a stack', err)
|
|
console.warn('FetchDebugger - overriding stack to point of original call')
|
|
err.stack = initialStack
|
|
}
|
|
throw err
|
|
}
|
|
}
|
|
}
|
|
|
|
function getCurrentStack () {
|
|
try {
|
|
throw new Error('Fake error for generating stack trace')
|
|
} catch (err) {
|
|
return err.stack
|
|
}
|
|
}
|