From 4c0386b2c5887c89cbe94ccb9d75964d2fc00c5b Mon Sep 17 00:00:00 2001 From: SuZhou-Joe Date: Fri, 5 Jan 2024 17:35:12 +0800 Subject: [PATCH] fix: bypass real error info from backend (#92) * feat: throw error from backend Signed-off-by: SuZhou-Joe * feat: optimize logic Signed-off-by: SuZhou-Joe --------- Signed-off-by: SuZhou-Joe --- server/routes/chat_routes.ts | 5 +---- server/routes/send_message.test.ts | 24 ++++++++++-------------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/server/routes/chat_routes.ts b/server/routes/chat_routes.ts index 70551f4c..645f1cc1 100644 --- a/server/routes/chat_routes.ts +++ b/server/routes/chat_routes.ts @@ -166,10 +166,7 @@ export function registerChatRoutes(router: IRouter, routeOptions: RoutesOptions) }); } catch (error) { context.assistant_plugin.logger.error(error); - const sessionId = outputs?.memoryId || sessionIdInRequestBody; - if (!sessionId) { - return response.custom({ statusCode: error.statusCode || 500, body: error.message }); - } + return response.custom({ statusCode: error.statusCode || 500, body: error.message }); } /** diff --git a/server/routes/send_message.test.ts b/server/routes/send_message.test.ts index 00c4e575..4a368044 100644 --- a/server/routes/send_message.test.ts +++ b/server/routes/send_message.test.ts @@ -183,7 +183,7 @@ describe('send_message route when rootAgentName is provided', () => { `); }); - it('return successfully when requestLLM throws an error but conversation id provided', async () => { + it('throw error when requestLLM throws an error', async () => { mockOllyChatService.requestLLM.mockImplementationOnce(() => { throw new Error('something went wrong'); }); @@ -209,21 +209,17 @@ describe('send_message route when rootAgentName is provided', () => { }, }, sessionId: 'foo', - })) as ResponseObject; + })) as Boom; expect(mockedLogger.error).toBeCalledWith(new Error('something went wrong')); - expect(result.source).toMatchInlineSnapshot(` + expect(result.output).toMatchInlineSnapshot(` Object { - "interactions": Array [ - Object { - "conversation_id": "foo", - "create_time": "create_time", - "input": "foo", - "interaction_id": "interaction_id", - "response": "bar", - }, - ], - "messages": Array [], - "sessionId": "foo", + "headers": Object {}, + "payload": Object { + "error": "Internal Server Error", + "message": "something went wrong", + "statusCode": 500, + }, + "statusCode": 500, } `); });