@lobehub/chat
Version:
Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.
27 lines (22 loc) • 740 B
text/typescript
import { t } from 'i18next';
import { ErrorResponse, ErrorType } from '@/types/fetch';
import { ChatMessageError } from '@/types/message';
export const getMessageError = async (response: Response) => {
let chatMessageError: ChatMessageError;
// try to get the biz error
try {
const data = (await response.json()) as ErrorResponse;
chatMessageError = {
body: data.body,
message: t(`response.${data.errorType}` as any, { ns: 'error' }),
type: data.errorType,
};
} catch {
// if not return, then it's a common error
chatMessageError = {
message: t(`response.${response.status}` as any, { ns: 'error' }),
type: response.status as ErrorType,
};
}
return chatMessageError;
};