Skip to content

Commit 62881fe

Browse files
authored
🔧 fix: handle missing custom config speech (danny-avila#3790)
* 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
1 parent 34fd960 commit 62881fe

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

api/server/services/Files/Audio/getCustomConfigSpeech.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const getCustomConfig = require('~/server/services/Config/getCustomConfig');
2+
const { logger } = require('~/config');
23

34
/**
45
* This function retrieves the speechTab settings from the custom configuration
@@ -15,14 +16,21 @@ const getCustomConfig = require('~/server/services/Config/getCustomConfig');
1516
async function getCustomConfigSpeech(req, res) {
1617
try {
1718
const customConfig = await getCustomConfig();
19+
20+
if (!customConfig) {
21+
return res.status(200).send({
22+
message: 'not_found',
23+
});
24+
}
25+
1826
const sttExternal = !!customConfig.speech?.stt;
1927
const ttsExternal = !!customConfig.speech?.tts;
2028
let settings = {
2129
sttExternal,
2230
ttsExternal,
2331
};
2432

25-
if (!customConfig || !customConfig.speech?.speechTab) {
33+
if (!customConfig.speech?.speechTab) {
2634
return res.status(200).send(settings);
2735
}
2836

@@ -50,7 +58,7 @@ async function getCustomConfigSpeech(req, res) {
5058

5159
return res.status(200).send(settings);
5260
} catch (error) {
53-
console.error('Failed to get custom config speech settings:', error);
61+
logger.error('Failed to get custom config speech settings:', error);
5462
res.status(500).send('Internal Server Error');
5563
}
5664
}

client/src/components/Nav/SettingsTabs/Speech/Speech.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ function Speech() {
127127
);
128128

129129
useEffect(() => {
130-
if (data) {
130+
if (data && data.message !== 'not_found') {
131131
Object.entries(data).forEach(([key, value]) => {
132132
updateSetting(key, value);
133133
});

0 commit comments

Comments
 (0)