Handle non-JSON responses in login flow

This commit is contained in:
2025-09-24 10:30:13 +02:00
parent 3217ed5871
commit f06cfb81dd
2 changed files with 10 additions and 2 deletions
+10 -1
View File
@@ -40,7 +40,16 @@
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username, password })
});
const data = await res.json();
let data;
const ct = res.headers.get('content-type') || '';
if (ct.includes('application/json')) {
data = await res.json();
} else {
const text = await res.text();
data = { ok: res.ok, error: text || res.statusText };
}
if (res.ok && data.ok) {
msg.textContent = 'Erfolgreich authentifiziert!';
} else {