handleResponse gibt ein objekt mit ok und json zurück

This commit is contained in:
Technoir committed 2026-10-17 15:06:56 +02:00
1 parent 9f63b689fc
commit 719f633615
1 file changed
+3 -5
@@ -1,21 +1,19 @@
import { showError } from "./error.js";
export async function handleResponse(promise, errorMsg) {
const response = await promise;
//weil 204 kein body ist un damit unparsbar, geben wir vorab true zurück
if (response.status == 204) {
return true;
return { ok: true, json: null };
}
const json = await response.json();
if (!response.ok) {
showError(json.msg);
console.error(errorMsg);
return false;
return { ok: false, json: json };
}
return json;
return { ok: true, json: json };
}