From 62881fee54b6b4c86f2994413cf32e80899809fe Mon Sep 17 00:00:00 2001 From: Marco Beretta <81851188+berry-13@users.noreply.github.com> Date: Tue, 27 Aug 2024 06:09:04 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20fix:=20handle=20missing=20custom?= =?UTF-8?q?=20config=20speech=20(#3790)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Update speech settings retrieval logic to handle missing custom configuration This commit updates the logic in the Speech component and the getCustomConfigSpeech function to handle the case where the custom configuration is missing. Previously, if no custom configuration was found, an error would occur. Now, the code checks for the presence of the custom configuration and returns a message indicating that no custom configuration was found. This improves the robustness of the application and provides a better user experience. * refactor: changed response message when no custom config is found --- .../services/Files/Audio/getCustomConfigSpeech.js | 12 ++++++++++-- .../components/Nav/SettingsTabs/Speech/Speech.tsx | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/api/server/services/Files/Audio/getCustomConfigSpeech.js b/api/server/services/Files/Audio/getCustomConfigSpeech.js index d22a143574..a0fd23e3fa 100644 --- a/api/server/services/Files/Audio/getCustomConfigSpeech.js +++ b/api/server/services/Files/Audio/getCustomConfigSpeech.js @@ -1,4 +1,5 @@ const getCustomConfig = require('~/server/services/Config/getCustomConfig'); +const { logger } = require('~/config'); /** * This function retrieves the speechTab settings from the custom configuration @@ -15,6 +16,13 @@ const getCustomConfig = require('~/server/services/Config/getCustomConfig'); async function getCustomConfigSpeech(req, res) { try { const customConfig = await getCustomConfig(); + + if (!customConfig) { + return res.status(200).send({ + message: 'not_found', + }); + } + const sttExternal = !!customConfig.speech?.stt; const ttsExternal = !!customConfig.speech?.tts; let settings = { @@ -22,7 +30,7 @@ async function getCustomConfigSpeech(req, res) { ttsExternal, }; - if (!customConfig || !customConfig.speech?.speechTab) { + if (!customConfig.speech?.speechTab) { return res.status(200).send(settings); } @@ -50,7 +58,7 @@ async function getCustomConfigSpeech(req, res) { return res.status(200).send(settings); } catch (error) { - console.error('Failed to get custom config speech settings:', error); + logger.error('Failed to get custom config speech settings:', error); res.status(500).send('Internal Server Error'); } } diff --git a/client/src/components/Nav/SettingsTabs/Speech/Speech.tsx b/client/src/components/Nav/SettingsTabs/Speech/Speech.tsx index 6ae78c0655..779c32ef93 100644 --- a/client/src/components/Nav/SettingsTabs/Speech/Speech.tsx +++ b/client/src/components/Nav/SettingsTabs/Speech/Speech.tsx @@ -127,7 +127,7 @@ function Speech() { ); useEffect(() => { - if (data) { + if (data && data.message !== 'not_found') { Object.entries(data).forEach(([key, value]) => { updateSetting(key, value); });