From 930e62f3d74a38b98fae09e5375ea552177484c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Gu=CC=88nther?= Date: Wed, 3 Jan 2024 18:46:36 +0100 Subject: [PATCH 1/2] BUGFIX: Prevent json encode error --- .../Terminal/src/helpers/fetchCommands.ts | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/Resources/Private/JavaScript/Terminal/src/helpers/fetchCommands.ts b/Resources/Private/JavaScript/Terminal/src/helpers/fetchCommands.ts index 1bf5283..7cb43c3 100644 --- a/Resources/Private/JavaScript/Terminal/src/helpers/fetchCommands.ts +++ b/Resources/Private/JavaScript/Terminal/src/helpers/fetchCommands.ts @@ -14,7 +14,29 @@ const fetchCommands = async (endPoint: string): Promise<{ success: boolean; resu 'Content-Type': 'application/json', }, })) - .then((response: Response) => response && response.json()) + .then((response: Response) => { + if (!response.ok) { + return { + success: false, + result: [], + }; + } + + return ( + response && + response + .json() + .then((data: CommandList) => { + return data; + }) + .catch((error: Error) => { + return { + success: false, + result: [], + }; + }) + ); + }) .catch((error: Error) => { logToConsole('error', error.message); return { From ab9f7c5fbfa48767d3062f48babfa727d9cc6e04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Gu=CC=88nther?= Date: Wed, 10 Jan 2024 09:42:38 +0100 Subject: [PATCH 2/2] TASK: Return empty objects instead of an array --- .../JavaScript/Terminal/src/helpers/fetchCommands.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Resources/Private/JavaScript/Terminal/src/helpers/fetchCommands.ts b/Resources/Private/JavaScript/Terminal/src/helpers/fetchCommands.ts index 7cb43c3..e862c62 100644 --- a/Resources/Private/JavaScript/Terminal/src/helpers/fetchCommands.ts +++ b/Resources/Private/JavaScript/Terminal/src/helpers/fetchCommands.ts @@ -18,7 +18,7 @@ const fetchCommands = async (endPoint: string): Promise<{ success: boolean; resu if (!response.ok) { return { success: false, - result: [], + result: {}, }; } @@ -32,7 +32,7 @@ const fetchCommands = async (endPoint: string): Promise<{ success: boolean; resu .catch((error: Error) => { return { success: false, - result: [], + result: {}, }; }) ); @@ -41,7 +41,7 @@ const fetchCommands = async (endPoint: string): Promise<{ success: boolean; resu logToConsole('error', error.message); return { success: false, - result: [], + result: {}, }; }); };