From bdfc648f514c0238447b44e1cd85bc68b529ac25 Mon Sep 17 00:00:00 2001 From: 2mal3 <56305732+2mal3@users.noreply.github.com> Date: Sun, 4 Jan 2026 21:29:25 +0100 Subject: [PATCH] chore(control): only try getting description if json response --- control/frontend/src/lib/ts/api_handler.ts | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/control/frontend/src/lib/ts/api_handler.ts b/control/frontend/src/lib/ts/api_handler.ts index a0b7f50..f8ecece 100755 --- a/control/frontend/src/lib/ts/api_handler.ts +++ b/control/frontend/src/lib/ts/api_handler.ts @@ -229,19 +229,16 @@ async function request( return request_response; } - let error_description: string; - try { - const json: { description: string } = await response.json(); - error_description = json.description; - } catch (error_on_json_parsing: unknown) { - error_description = `unknown error: ${error_on_json_parsing}`; + let error_description = url; + if (response.headers.get('content-type')?.includes('application/json')) { + try { + const json: { description: string } = await response.json(); + error_description += '\n' + json.description; + } catch { + error_description += '\nCould not parse error description'; + } } - console.error(url, error_description); - notifications.push( - 'error', - `Fehler ${response.status} bei API-Anfrage`, - `${url}\nFehler: ${error_description}` - ); + notifications.push('error', `Fehler ${response.status} bei API-Anfrage`, error_description); } catch (error: unknown) { if (error instanceof TypeError && /fetch|NetworkError/i.test(error.message)) { if (dev) {