From 4214e7dbb7b3f257723a9518b8d09058295d0dc5 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 14 Feb 2025 03:16:04 +0000 Subject: [PATCH] 500 error if workspace is invalid (#429) * Add feature changes for 500 Error Invalid Workspace Signed-off-by: hutiechuan * doc: add release notes for 2.19 (#426) Signed-off-by: Tianyu Gao * Add i18n for error message Signed-off-by: hutiechuan * no edit Signed-off-by: hutiechuan * change error_handler Signed-off-by: hutiechuan * revert yarn.lock and change error_handler Signed-off-by: hutiechuan * revert yarn.lock and change error_handler Signed-off-by: hutiechuan * removing the customized error Signed-off-by: hutiechuan * removing unnecessary logs Signed-off-by: hutiechuan * update yarn.lock fronm main branch and clean up my local branch Signed-off-by: hutiechuan * clean my current code Signed-off-by: hutiechuan * add changelog Signed-off-by: hutiechuan * Update server/routes/error_handler.ts Signed-off-by: Yulong Ruan --------- Signed-off-by: Tianyu Gao Signed-off-by: hutiechuan Signed-off-by: Yulong Ruan Co-authored-by: hutiechuan Co-authored-by: Tianyu Gao Co-authored-by: Yulong Ruan (cherry picked from commit d3c315f299a53aa87d3b8f3cb1b3b267d61e63fa) Signed-off-by: github-actions[bot] # Conflicts: # CHANGELOG.md --- package.json | 2 +- server/routes/error_handler.ts | 6 +++++- server/routes/summary_routes.ts | 13 +++++++------ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 7349f9a9..80b19a03 100644 --- a/package.json +++ b/package.json @@ -45,4 +45,4 @@ "micromatch": "^4.0.8", "cross-spawn": "^7.0.5" } -} \ No newline at end of file +} diff --git a/server/routes/error_handler.ts b/server/routes/error_handler.ts index f8c4f017..21cc6c95 100644 --- a/server/routes/error_handler.ts +++ b/server/routes/error_handler.ts @@ -17,8 +17,12 @@ export const handleError = (e: any, res: OpenSearchDashboardsResponseFactory, lo // handle http response error of calling backend API if (e.statusCode) { if (e.statusCode >= 400 && e.statusCode <= 499) { + let message = typeof e.body === 'string' ? e.body : JSON.stringify(e.body); + if (!message) { + message = e.message; + } return res.customError({ - body: { message: typeof e.body === 'string' ? e.body : JSON.stringify(e.body) }, + body: { message: message || 'unknow error' }, statusCode: e.statusCode, }); } else { diff --git a/server/routes/summary_routes.ts b/server/routes/summary_routes.ts index 962e8e1a..f12a3eb1 100644 --- a/server/routes/summary_routes.ts +++ b/server/routes/summary_routes.ts @@ -98,13 +98,14 @@ export function registerSummaryAssistantRoutes( }, }, router.handleLegacyErrors(async (context, req, res) => { - const client = await getOpenSearchClientTransport({ - context, - dataSourceId: req.query.dataSourceId, - }); - const assistantClient = assistantService.getScopedClient(req, context); - try { + const client = await getOpenSearchClientTransport({ + context, + dataSourceId: req.query.dataSourceId, + }); + + const assistantClient = assistantService.getScopedClient(req, context); + const insightAgentId = await detectInsightAgentId( req.body.insightType, req.body.summaryType,