diff options
author | Whymarrh Whitby <whymarrh.whitby@gmail.com> | 2018-10-18 04:08:55 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-18 04:08:55 +0800 |
commit | 0d0bb4afd741f5f14ebbfca87849091dcffa895f (patch) | |
tree | 443d85b657a592ea4038f30a7963dee4aa84cc1c /app | |
parent | badebe017fe28b58ac742082368484c3a4b1c1bc (diff) | |
parent | 70c45ae8be4827415c218a8b527fd0a6d420a7ba (diff) | |
download | tangerine-wallet-browser-0d0bb4afd741f5f14ebbfca87849091dcffa895f.tar tangerine-wallet-browser-0d0bb4afd741f5f14ebbfca87849091dcffa895f.tar.gz tangerine-wallet-browser-0d0bb4afd741f5f14ebbfca87849091dcffa895f.tar.bz2 tangerine-wallet-browser-0d0bb4afd741f5f14ebbfca87849091dcffa895f.tar.lz tangerine-wallet-browser-0d0bb4afd741f5f14ebbfca87849091dcffa895f.tar.xz tangerine-wallet-browser-0d0bb4afd741f5f14ebbfca87849091dcffa895f.tar.zst tangerine-wallet-browser-0d0bb4afd741f5f14ebbfca87849091dcffa895f.zip |
Merge pull request #5522 from MetaMask/fetch-debugging
debugging - enable fetch debugging
Diffstat (limited to 'app')
-rw-r--r-- | app/scripts/background.js | 3 | ||||
-rw-r--r-- | app/scripts/lib/setupFetchDebugging.js | 34 |
2 files changed, 37 insertions, 0 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js index 0343e134c..509a0001d 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -2,6 +2,9 @@ * @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 endOfStream = require('end-of-stream') const pump = require('pump') diff --git a/app/scripts/lib/setupFetchDebugging.js b/app/scripts/lib/setupFetchDebugging.js new file mode 100644 index 000000000..dd87b65a6 --- /dev/null +++ b/app/scripts/lib/setupFetchDebugging.js @@ -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 + } +} |