From 0c84f94f319fb5bcc6e2768d783eaa878aec2113 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Sun, 14 Nov 2021 15:04:35 +0100 Subject: [PATCH] Improve error handling App will no longer crash, if the error response cannot be parsed (e.g. when API is down). --- app.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app.ts b/app.ts index c2e187b..7aec761 100644 --- a/app.ts +++ b/app.ts @@ -122,7 +122,11 @@ async function message_id(teamspeakID: string, msg: string) { } function get_error(e: unknown): string { - return JSON.parse(JSON.stringify(e)).response.errors[0].message; + try { + return JSON.parse(JSON.stringify(e)).response.errors[0].message; + } catch { + return e as string; + } } async function request(query: string, variables?: Variables): Promise { -- 2.44.0