aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/helpers/utils/fetch.js
diff options
context:
space:
mode:
Diffstat (limited to 'ui/app/helpers/utils/fetch.js')
-rw-r--r--ui/app/helpers/utils/fetch.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/ui/app/helpers/utils/fetch.js b/ui/app/helpers/utils/fetch.js
new file mode 100644
index 000000000..7bb483818
--- /dev/null
+++ b/ui/app/helpers/utils/fetch.js
@@ -0,0 +1,25 @@
+/* global AbortController */
+
+export default function ({ timeout = 120000 } = {}) {
+ return function _fetch (url, opts) {
+ return new Promise(async (resolve, reject) => {
+ const abortController = new AbortController()
+ const abortSignal = abortController.signal
+ const f = fetch(url, {
+ ...opts,
+ signal: abortSignal,
+ })
+
+ const timer = setTimeout(() => abortController.abort(), timeout)
+
+ try {
+ const res = await f
+ clearTimeout(timer)
+ return resolve(res)
+ } catch (e) {
+ clearTimeout(timer)
+ return reject(e)
+ }
+ })
+ }
+}