1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-30 08:09:15 +01:00
metamask-extension/app/scripts/lib/setupFetchDebugging.js

37 lines
965 B
JavaScript
Raw Normal View History

2018-10-15 07:14:25 +02:00
module.exports = 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
2018-10-15 07:14:25 +02:00
// https://github.com/getsentry/sentry-javascript/pull/1293
//
function setupFetchDebugging () {
2018-10-15 07:14:25 +02:00
if (!global.fetch) return
const originalFetch = global.fetch
global.fetch = wrappedFetch
async function wrappedFetch (...args) {
2018-10-15 07:14:25 +02:00
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
}
2018-10-15 07:14:25 +02:00
throw err
}
}
}
function getCurrentStack () {
2018-10-15 07:14:25 +02:00
try {
throw new Error('Fake error for generating stack trace')
} catch (err) {
return err.stack
}
}