feat(download): update fetch requests to use JSON format and improve error handling

This commit is contained in:
MasterAcnolo
2026-10-28 21:48:47 +01:00
parent 0699656394
commit fdfe30e796
2 changed files with 47 additions and 11 deletions

View File

@@ -32,14 +32,27 @@ async function fetchVideoInfo(url) {
try {
const res = await fetch(`/info?url=${encodeURIComponent(url)}`, {
method: "GET",
headers: {"Accept": "application/json"}
headers: {Accept: "application/json"},
});
const data = await res.json();
let data;
try {
data = await res.json();
} catch (e) {
return {error: "Network or JSON Issue"};
}
if (!res.ok) return {error: `An Error occured when fetching info`};
if (!res.ok) {
if (data && data.error) {
return {error: data.error.message || "An Error occured when fetching info"};
}
return {error: "An Error occured when fetching info"};
}
if (!data) return { error: "Data is Missing" };
if (data.error) {
return {error: data.error.message || data.error};
}
return data;
} catch (e) {