aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib
diff options
context:
space:
mode:
authorbrunobar79 <brunobar79@gmail.com>2018-10-21 13:59:53 +0800
committerbrunobar79 <brunobar79@gmail.com>2018-10-21 13:59:53 +0800
commit9c1b2108f69334884473eb95758e2d1c02c984d6 (patch)
tree93f5255399307a28cb9380dc23c275b406403929 /app/scripts/lib
parent13820b6cc1801a420f39cdfecd7ccb5309dc597b (diff)
parentb0c649a4e3c68293e08e764bbf4d53939df88e2d (diff)
downloadtangerine-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.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
+ }
+}