mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Merge pull request #5522 from MetaMask/fetch-debugging
debugging - enable fetch debugging
This commit is contained in:
commit
0d0bb4afd7
@ -2,6 +2,9 @@
|
|||||||
* @file The entry point for the web extension singleton process.
|
* @file The entry point for the web extension singleton process.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// this needs to run before anything else
|
||||||
|
require('./lib/setupFetchDebugging')()
|
||||||
|
|
||||||
const urlUtil = require('url')
|
const urlUtil = require('url')
|
||||||
const endOfStream = require('end-of-stream')
|
const endOfStream = require('end-of-stream')
|
||||||
const pump = require('pump')
|
const pump = require('pump')
|
||||||
|
34
app/scripts/lib/setupFetchDebugging.js
Normal file
34
app/scripts/lib/setupFetchDebugging.js
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
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
|
||||||
|
// 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) {
|
||||||
|
console.warn('FetchDebugger - fetch encountered an Error', 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
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user