mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
🔧 refactor: customUserVar Error Normalization (#8950)
* fix: localization string had unused template var * fix: add normalizeHttpError to hopefully stop UI hangs when an error is returned in UserController - Ensures updateUserPluginsController always returns valid HTTP status codes instead of undefined - Add normalizeHttpError() helper to safely extract status/message from errors - Default to 400 status code when Error.status is undefined/invalid * refactor: move normalizeHttpError to packages/api
This commit is contained in:
parent
5d0bc95193
commit
9ca1847535
4 changed files with 36 additions and 8 deletions
|
|
@ -1,5 +1,5 @@
|
|||
const { logger } = require('@librechat/data-schemas');
|
||||
const { webSearchKeys, extractWebSearchEnvVars } = require('@librechat/api');
|
||||
const { webSearchKeys, extractWebSearchEnvVars, normalizeHttpError } = require('@librechat/api');
|
||||
const {
|
||||
getFiles,
|
||||
updateUser,
|
||||
|
|
@ -89,8 +89,8 @@ const updateUserPluginsController = async (req, res) => {
|
|||
|
||||
if (userPluginsService instanceof Error) {
|
||||
logger.error('[userPluginsService]', userPluginsService);
|
||||
const { status, message } = userPluginsService;
|
||||
res.status(status).send({ message });
|
||||
const { status, message } = normalizeHttpError(userPluginsService);
|
||||
return res.status(status).send({ message });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -137,7 +137,7 @@ const updateUserPluginsController = async (req, res) => {
|
|||
authService = await updateUserPluginAuth(user.id, keys[i], pluginKey, values[i]);
|
||||
if (authService instanceof Error) {
|
||||
logger.error('[authService]', authService);
|
||||
({ status, message } = authService);
|
||||
({ status, message } = normalizeHttpError(authService));
|
||||
}
|
||||
}
|
||||
} else if (action === 'uninstall') {
|
||||
|
|
@ -151,7 +151,7 @@ const updateUserPluginsController = async (req, res) => {
|
|||
`[authService] Error deleting all auth for MCP tool ${pluginKey}:`,
|
||||
authService,
|
||||
);
|
||||
({ status, message } = authService);
|
||||
({ status, message } = normalizeHttpError(authService));
|
||||
}
|
||||
} else {
|
||||
// This handles:
|
||||
|
|
@ -163,7 +163,7 @@ const updateUserPluginsController = async (req, res) => {
|
|||
authService = await deleteUserPluginAuth(user.id, keys[i]); // Deletes by authField name
|
||||
if (authService instanceof Error) {
|
||||
logger.error('[authService] Error deleting specific auth key:', authService);
|
||||
({ status, message } = authService);
|
||||
({ status, message } = normalizeHttpError(authService));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -193,7 +193,8 @@ const updateUserPluginsController = async (req, res) => {
|
|||
return res.status(status).send();
|
||||
}
|
||||
|
||||
res.status(status).send({ message });
|
||||
const normalized = normalizeHttpError({ status, message });
|
||||
return res.status(normalized.status).send({ message: normalized.message });
|
||||
} catch (err) {
|
||||
logger.error('[updateUserPluginsController]', err);
|
||||
return res.status(500).json({ message: 'Something went wrong.' });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue