mirror of
https://github.com/wukko/cobalt.git
synced 2025-02-03 00:46:19 +01:00
web/api: remove deprecated statuses, update error type, time out request
also updated some error codes
This commit is contained in:
parent
f96c1cd13b
commit
ac6d68ec45
3 changed files with 24 additions and 9 deletions
|
@ -68,16 +68,16 @@
|
||||||
|
|
||||||
return createDialog({
|
return createDialog({
|
||||||
...defaultErrorPopup,
|
...defaultErrorPopup,
|
||||||
bodyText: "couldn't access the api",
|
bodyText: $t("error.api.unreachable"),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.status === "error" || response.status === "rate-limit") {
|
if (response.status === "error") {
|
||||||
changeDownloadButton("error");
|
changeDownloadButton("error");
|
||||||
|
|
||||||
return createDialog({
|
return createDialog({
|
||||||
...defaultErrorPopup,
|
...defaultErrorPopup,
|
||||||
bodyText: response.text,
|
bodyText: $t(response.error.code),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@
|
||||||
|
|
||||||
return createDialog({
|
return createDialog({
|
||||||
...defaultErrorPopup,
|
...defaultErrorPopup,
|
||||||
bodyText: "couldn't probe the stream",
|
bodyText: $t("error.stream.failed_probe"),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -139,7 +139,7 @@
|
||||||
|
|
||||||
return createDialog({
|
return createDialog({
|
||||||
...defaultErrorPopup,
|
...defaultErrorPopup,
|
||||||
bodyText: "unknown/unsupported status",
|
bodyText: $t("error.api.unknown_response"),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -91,12 +91,22 @@ const request = async (url: string) => {
|
||||||
const response: Optional<CobaltAPIResponse> = await fetch(api, {
|
const response: Optional<CobaltAPIResponse> = await fetch(api, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
redirect: "manual",
|
redirect: "manual",
|
||||||
|
signal: AbortSignal.timeout(10000),
|
||||||
body: JSON.stringify(request),
|
body: JSON.stringify(request),
|
||||||
headers: {
|
headers: {
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
}).then(r => r.json()).catch(() => {});
|
}).then(r => r.json()).catch((e) => {
|
||||||
|
if (e?.message?.includes("timed out")) {
|
||||||
|
return {
|
||||||
|
status: "error",
|
||||||
|
error: {
|
||||||
|
code: "error.api.timed_out"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,19 @@
|
||||||
enum CobaltResponseType {
|
enum CobaltResponseType {
|
||||||
Error = 'error',
|
Error = 'error',
|
||||||
RateLimit = 'rate-limit',
|
|
||||||
Picker = 'picker',
|
Picker = 'picker',
|
||||||
Redirect = 'redirect',
|
Redirect = 'redirect',
|
||||||
Stream = 'stream',
|
Stream = 'stream',
|
||||||
}
|
}
|
||||||
|
|
||||||
type CobaltErrorResponse = {
|
type CobaltErrorResponse = {
|
||||||
status: CobaltResponseType.Error | CobaltResponseType.RateLimit,
|
status: CobaltResponseType.Error,
|
||||||
text: string,
|
error: {
|
||||||
|
code: string,
|
||||||
|
context?: {
|
||||||
|
service?: string,
|
||||||
|
limit?: number,
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
type CobaltPartialURLResponse = {
|
type CobaltPartialURLResponse = {
|
||||||
|
|
Loading…
Reference in a new issue