aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/setupFetchDebugging.js
diff options
context:
space:
mode:
authorkumavis <kumavis@users.noreply.github.com>2018-10-18 08:30:07 +0800
committerGitHub <noreply@github.com>2018-10-18 08:30:07 +0800
commitc2f97717c0fbf9a64cf527891f7a1f35049fb023 (patch)
treef62dabf7a62798ad82641305422fb4e0bcc0a74a /app/scripts/lib/setupFetchDebugging.js
parent85884b21afe6e5e85b58123b24e72776d1437cc6 (diff)
parent17372e150d7070e9f4870e65a7d6c1d88568f2f5 (diff)
downloadtangerine-wallet-browser-c2f97717c0fbf9a64cf527891f7a1f35049fb023.tar.gz
tangerine-wallet-browser-c2f97717c0fbf9a64cf527891f7a1f35049fb023.tar.zst
tangerine-wallet-browser-c2f97717c0fbf9a64cf527891f7a1f35049fb023.zip
Merge pull request #5539 from MetaMask/v4.16.0
Version 4.16.0
Diffstat (limited to 'app/scripts/lib/setupFetchDebugging.js')
-rw-r--r--app/scripts/lib/setupFetchDebugging.js34
1 files changed, 34 insertions, 0 deletions
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
+ }
+}