perf:提示文案;错误处理

This commit is contained in:
Archer
2023-03-13 19:48:19 +08:00
parent b204c55bd1
commit 138b607ac7
6 changed files with 13 additions and 26 deletions

View File

@@ -18,6 +18,9 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
res.on('close', () => {
res.end();
});
req.on('error', () => {
res.end();
});
const { chatId, windowId } = req.query as { chatId: string; windowId: string };
@@ -114,14 +117,9 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
}
};
try {
for await (const chunk of chatResponse.data as any) {
const parser = createParser(onParse);
parser.feed(decoder.decode(chunk));
}
} catch (error) {
console.log(error, '====');
throw new Error('错误了');
for await (const chunk of chatResponse.data as any) {
const parser = createParser(onParse);
parser.feed(decoder.decode(chunk));
}
} catch (err: any) {
console.log('error->', err?.response, '===');