Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only parse json if response content type is set #298

Merged
merged 4 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
31 changes: 18 additions & 13 deletions src/Geopilot.Frontend/src/pages/admin/deliveryOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,24 @@ export const DeliveryOverview = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

async function handleDelete() {
for (const row of selectedRows) {
fetchApi("/api/v1/delivery/" + row, { method: "DELETE" }).catch((error: ApiError) => {
if (error.status === 404) {
showAlert(t("deliveryOverviewDeleteIdNotExistError", { id: row }), "error");
} else if (error.status === 500) {
showAlert(t("deliveryOverviewDeleteIdError", { id: row }), "error");
} else {
showAlert(t("deliveryOverviewDeleteError", { error: error }), "error");
}
});
}
await loadDeliveries();
function handleDelete() {
const deletePromises = selectedRows.map(row =>
fetchApi("/api/v1/delivery/" + row, { method: "DELETE" })
.then(() => null)
tschumpr marked this conversation as resolved.
Show resolved Hide resolved
.catch((error: ApiError) => {
if (error.status === 404) {
showAlert(t("deliveryOverviewDeleteIdNotExistError", { id: row }), "error");
} else if (error.status === 500) {
showAlert(t("deliveryOverviewDeleteIdError", { id: row }), "error");
} else {
showAlert(t("deliveryOverviewDeleteError", { error: error }), "error");
}
}),
);

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

return (
Expand Down