diff options
author | brunobar79 <brunobar79@gmail.com> | 2018-10-21 13:59:53 +0800 |
---|---|---|
committer | brunobar79 <brunobar79@gmail.com> | 2018-10-21 13:59:53 +0800 |
commit | 9c1b2108f69334884473eb95758e2d1c02c984d6 (patch) | |
tree | 93f5255399307a28cb9380dc23c275b406403929 /app/scripts/lib | |
parent | 13820b6cc1801a420f39cdfecd7ccb5309dc597b (diff) | |
parent | b0c649a4e3c68293e08e764bbf4d53939df88e2d (diff) | |
download | tangerine-wallet-browser-9c1b2108f69334884473eb95758e2d1c02c984d6.tar.gz tangerine-wallet-browser-9c1b2108f69334884473eb95758e2d1c02c984d6.tar.zst tangerine-wallet-browser-9c1b2108f69334884473eb95758e2d1c02c984d6.zip |
fix merge conflicts
Diffstat (limited to 'app/scripts/lib')
-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 + } +} |