From 5d38348833687a3fd713048bc984ea45fe5a0989 Mon Sep 17 00:00:00 2001 From: xiang <1984871009@qq.com> Date: Sun, 7 May 2023 20:20:27 +0800 Subject: [PATCH] feat: more err log --- index.ts | 9 +++++---- model/forefront/index.ts | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/index.ts b/index.ts index e9dac0e..f01dcc6 100644 --- a/index.ts +++ b/index.ts @@ -9,8 +9,9 @@ const errorHandler = async (ctx: Context, next: Next) => { try { await next(); } catch (err:any) { - ctx.response.status = err.status || 500; - ctx.response.body = err; + console.error(err); + ctx.body = JSON.stringify(err); + ctx.res.end(); } }; app.use(errorHandler); @@ -34,7 +35,7 @@ router.get('/ask', async (ctx) => { return; } const res = await chat.ask({prompt: prompt as string, options}); - ctx.body = res.text; + ctx.body = res?.text; }); router.get('/ask/stream', async (ctx) => { @@ -54,7 +55,7 @@ router.get('/ask/stream', async (ctx) => { "Connection": "keep-alive", }); const res = await chat.askStream({prompt: prompt as string, options}); - ctx.body = res.text; + ctx.body = res?.text; }) app.use(router.routes()); diff --git a/model/forefront/index.ts b/model/forefront/index.ts index 41fce28..238c921 100644 --- a/model/forefront/index.ts +++ b/model/forefront/index.ts @@ -149,7 +149,7 @@ export class Forefront extends Chat { return; } const [{delta: {content}}] = data.choices; - cb(null, content); + cb(null, content||''); })) return {text: stream}; } catch (e: any) {