chore: refactor response error handling

This commit is contained in:
Ramires Viana
2022-05-04 12:11:36 +00:00
parent d1d7b23da6
commit 96afaca0ad
16 changed files with 61 additions and 93 deletions
+14 -18
View File
@@ -8,28 +8,24 @@ export async function fetch(url, password = "") {
headers: { "X-SHARE-PASSWORD": encodeURIComponent(password) },
});
if (res.status === 200) {
let data = await res.json();
data.url = `/share${url}`;
let data = await res.json();
data.url = `/share${url}`;
if (data.isDir) {
if (!data.url.endsWith("/")) data.url += "/";
data.items = data.items.map((item, index) => {
item.index = index;
item.url = `${data.url}${encodeURIComponent(item.name)}`;
if (data.isDir) {
if (!data.url.endsWith("/")) data.url += "/";
data.items = data.items.map((item, index) => {
item.index = index;
item.url = `${data.url}${encodeURIComponent(item.name)}`;
if (item.isDir) {
item.url += "/";
}
if (item.isDir) {
item.url += "/";
}
return item;
});
}
return data;
} else {
throw new Error(res.status);
return item;
});
}
return data;
}
export function download(format, hash, token, ...files) {