mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-27 00:17:31 +00:00
perf: 流响应
This commit is contained in:
@@ -4,3 +4,7 @@ export const openaiError: Record<string, string> = {
|
||||
rate_limit_reached: '同时访问用户过多,请稍后再试',
|
||||
'Bad Request': '上下文太多了,请重开对话~'
|
||||
};
|
||||
export const proxyError: Record<string, boolean> = {
|
||||
ECONNABORTED: true,
|
||||
ECONNRESET: true
|
||||
};
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { NextApiResponse } from 'next';
|
||||
import { openaiError } from './errorCode';
|
||||
import { openaiError, proxyError } from './errorCode';
|
||||
|
||||
export interface ResponseType<T = any> {
|
||||
code: number;
|
||||
@@ -23,12 +23,13 @@ export const jsonRes = (
|
||||
msg = error?.message || '请求错误';
|
||||
if (typeof error === 'string') {
|
||||
msg = error;
|
||||
} else if (error?.response?.data?.message in openaiError) {
|
||||
msg = openaiError[error?.response?.data?.message];
|
||||
} else if (proxyError[error?.code]) {
|
||||
msg = '服务器代理出错';
|
||||
} else if (openaiError[error?.response?.statusText]) {
|
||||
msg = openaiError[error.response.statusText];
|
||||
}
|
||||
|
||||
console.log('error->', error);
|
||||
console.log('error->', msg);
|
||||
console.log('error->', error.code, error?.response?.statusText, msg);
|
||||
}
|
||||
|
||||
res.json({
|
||||
|
Reference in New Issue
Block a user