diff options
author | kumavis <aaron@kumavis.me> | 2018-10-15 13:14:25 +0800 |
---|---|---|
committer | kumavis <aaron@kumavis.me> | 2018-10-15 13:14:25 +0800 |
commit | 70c45ae8be4827415c218a8b527fd0a6d420a7ba (patch) | |
tree | 84117998d0495be37bb7c47225f5f940c95fdd0f /app/scripts/lib/setupFetchDebugging.js | |
parent | 5504c8b9659f9345bb6d1b38d4d5ff91db1b6611 (diff) | |
download | tangerine-wallet-browser-70c45ae8be4827415c218a8b527fd0a6d420a7ba.tar.gz tangerine-wallet-browser-70c45ae8be4827415c218a8b527fd0a6d420a7ba.tar.zst tangerine-wallet-browser-70c45ae8be4827415c218a8b527fd0a6d420a7ba.zip |
enable fetch debugging
Diffstat (limited to 'app/scripts/lib/setupFetchDebugging.js')
-rw-r--r-- | app/scripts/lib/setupFetchDebugging.js | 34 |
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 + } +} |