mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-16 16:30: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
26
packages/api/src/utils/http.ts
Normal file
26
packages/api/src/utils/http.ts
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/**
|
||||
* Normalizes an error-like object into an HTTP status and message.
|
||||
* Ensures we always respond with a valid numeric status to avoid UI hangs.
|
||||
*/
|
||||
export function normalizeHttpError(
|
||||
err: Error | { status?: number; message?: string } | unknown,
|
||||
fallbackStatus = 400,
|
||||
) {
|
||||
let status = fallbackStatus;
|
||||
if (err && typeof err === 'object' && 'status' in err && typeof err.status === 'number') {
|
||||
status = err.status;
|
||||
}
|
||||
|
||||
let message = 'An error occurred.';
|
||||
if (
|
||||
err &&
|
||||
typeof err === 'object' &&
|
||||
'message' in err &&
|
||||
typeof err.message === 'string' &&
|
||||
err.message.length > 0
|
||||
) {
|
||||
message = err.message;
|
||||
}
|
||||
|
||||
return { status, message };
|
||||
}
|
||||
|
|
@ -12,3 +12,4 @@ export * from './openid';
|
|||
export * from './tempChatRetention';
|
||||
export { default as Tokenizer } from './tokenizer';
|
||||
export * from './yaml';
|
||||
export * from './http';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue