add loader

This commit is contained in:
kandrusyak
2022-08-22 17:05:05 +03:00
parent 79ca03823c
commit 369f0e375c
7 changed files with 297 additions and 83 deletions

View File

@@ -8,14 +8,19 @@ function prepareUrl(url) {
function handleRequest(method, url, headers, attempts, token, body) {
return new Promise((resolve, reject) => {
store.loading = true;
(function internalRequest() {
return request(method, url, headers, token, body)
.then(resolve)
.catch(err => --attempts > 0 ? internalRequest() : reject(err))
})()
})
.then((res) => res.json())
.then((res) => {
store.loading = false;
return res.json();
})
.catch((err) => {
store.loading = false;
console.log(err)
return {}
})