handleResponse gibt ein objekt mit ok und json zurück
This commit is contained in:
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 };
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user