Check status code when downloading files

pull/256/head
Candid Dauth 2024-03-02 00:37:29 +01:00
rodzic b7b70b6cf0
commit 9550c91dae
1 zmienionych plików z 8 dodań i 2 usunięć

Wyświetl plik

@ -465,14 +465,20 @@ function _formatAddress(result: NominatimResult) {
}
async function _loadUrl(url: string, completeOsmObjects = false): Promise<string> {
let bodyBuf = new Uint8Array(await fetch(
const res = await fetch(
url,
{
headers: {
"User-Agent": config.userAgent
}
}
).then<ArrayBuffer>(async (res) => await res.arrayBuffer()));
);
if (!res.ok) {
throw new Error(`Request to "${url}" failed with status ${res.status}.`);
}
let bodyBuf = new Uint8Array(await res.arrayBuffer());
if(!bodyBuf)
throw new Error("Invalid response from server.");