UNPKG

@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.

25 lines (21 loc) 720 B
import { ChatMessageError, ErrorResponse, ErrorType } from '@lobechat/types'; import { t } from 'i18next'; export const getMessageError = async (response: Response): Promise<ChatMessageError> => { 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}`, { ns: 'error' }), type: data.errorType, }; } catch { // if not return, then it's a common error chatMessageError = { message: t(`response.${response.status}`, { ns: 'error' }), type: response.status as ErrorType, }; } return chatMessageError; };