Skip to content

Commit

Permalink
Only parse json if response content type is set (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
tschumpr authored Sep 13, 2024
2 parents 692a5df + 714229e commit 1106b52
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Geopilot.Frontend/src/api/apiContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const ApiProvider: FC<PropsWithChildren> = ({ children }) => {

if (response.ok) {
const responseContentType = response.headers.get("content-type");
if (responseContentType?.indexOf("application/json") !== -1) {
if (responseContentType !== null && responseContentType?.indexOf("application/json") !== -1) {
return (await response.json()) as T;
} else if (!options.responseType || responseContentType?.includes(options.responseType)) {
return (await response.text()) as T;
Expand Down
13 changes: 8 additions & 5 deletions src/Geopilot.Frontend/src/pages/admin/deliveryOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ export const DeliveryOverview = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

async function handleDelete() {
for (const row of selectedRows) {
function handleDelete() {
const deletePromises = selectedRows.map(row =>
fetchApi("/api/v1/delivery/" + row, { method: "DELETE" }).catch((error: ApiError) => {
if (error.status === 404) {
showAlert(t("deliveryOverviewDeleteIdNotExistError", { id: row }), "error");
Expand All @@ -84,9 +84,12 @@ export const DeliveryOverview = () => {
} else {
showAlert(t("deliveryOverviewDeleteError", { error: error }), "error");
}
});
}
await loadDeliveries();
}),
);

Promise.all(deletePromises).then(() => {
loadDeliveries();
});
}

return (
Expand Down

0 comments on commit 1106b52

Please sign in to comment.