Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rzats committed Nov 21, 2024
1 parent 69b2d90 commit 64afa04
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/api/EpiData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ export function fetchImpl<T>(url: URL): Promise<T> {
const urlGetS = url.toString();
if (urlGetS.length < 4096) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return fetch(url.toString(), fetchOptions).then((d) => d.json());
return fetch(url.toString(), fetchOptions).then((d) => {
try {
return d.json();
} catch (error) {
throw new Error(`[${d.status}] ${d.text()}`);
}
});
}
const params = new URLSearchParams(url.searchParams);
url.searchParams.forEach((d) => url.searchParams.delete(d));
Expand All @@ -57,7 +63,13 @@ export function fetchImpl<T>(url: URL): Promise<T> {
...fetchOptions,
method: 'POST',
body: params,
}).then((d) => d.json());
}).then((d) => {
try {
return d.json();
} catch (error) {
throw new Error(`[${d.status}] ${d.text()}`);
}
});
}

// generic epidata loader
Expand Down Expand Up @@ -155,7 +167,7 @@ export function loadDataSet(
.alert(
`
<div class="uk-alert uk-alert-error">
<a href="${url.href}">API Link</a> returned no data.
<a href="${url.href}">API Link</a> returned no data, which suggests that the API has no available information for the selected location.
</div>`,
)
.then(() => null);
Expand Down

0 comments on commit 64afa04

Please sign in to comment.