mirror of
https://github.com/meowarex/TidaLuna-Plugins.git
synced 2026-06-18 03:43:10 +10:00
Forgot a Timeout <3
This commit is contained in:
@@ -1854,12 +1854,16 @@ const romanizeLinePayload = async (
|
|||||||
];
|
];
|
||||||
|
|
||||||
for (const url of urls) {
|
for (const url of urls) {
|
||||||
|
const controller = new AbortController();
|
||||||
|
const timeout = setTimeout(() => controller.abort(), 5000);
|
||||||
try {
|
try {
|
||||||
const res = await fetch(url, {
|
const res = await fetch(url, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "content-type": "application/json" },
|
headers: { "content-type": "application/json" },
|
||||||
body: JSON.stringify(payload),
|
body: JSON.stringify(payload),
|
||||||
|
signal: controller.signal,
|
||||||
});
|
});
|
||||||
|
clearTimeout(timeout);
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
trace.log(`Romanize: request failed ${res.status} from ${url}`);
|
trace.log(`Romanize: request failed ${res.status} from ${url}`);
|
||||||
continue;
|
continue;
|
||||||
@@ -1879,9 +1883,14 @@ const romanizeLinePayload = async (
|
|||||||
cachedTidalRomanizedLines = romanized;
|
cachedTidalRomanizedLines = romanized;
|
||||||
return romanized;
|
return romanized;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
clearTimeout(timeout);
|
||||||
|
if (err instanceof DOMException && err.name === "AbortError") {
|
||||||
|
trace.log(`Romanize: request timed out from ${url}`);
|
||||||
|
} else {
|
||||||
trace.log(`Romanize: request error from ${url}: ${err}`);
|
trace.log(`Romanize: request error from ${url}: ${err}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user