From 7fb989cd8da36ce2602f7c3e242d57c3cfcbae3a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 29 Oct 2024 22:23:42 +0000 Subject: [PATCH] [Discover] fix error handling in query enhancement facet (#8743) * [Discover] fix error handling in query enhancement facet --------- Signed-off-by: Joshua Li Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> (cherry picked from commit 2f319140d1de6d16b34f84d8359f4bb72421aa74) Signed-off-by: github-actions[bot] --- changelogs/fragments/8743.yml | 2 ++ src/plugins/query_enhancements/common/utils.ts | 3 ++- .../query_enhancements/server/search/ppl_search_strategy.ts | 1 + src/plugins/query_enhancements/server/utils/facet.ts | 2 +- 4 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/8743.yml diff --git a/changelogs/fragments/8743.yml b/changelogs/fragments/8743.yml new file mode 100644 index 000000000000..4ef81b73020b --- /dev/null +++ b/changelogs/fragments/8743.yml @@ -0,0 +1,2 @@ +fix: +- Fix error handling in query enhancement facet ([#8743](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8743)) \ No newline at end of file diff --git a/src/plugins/query_enhancements/common/utils.ts b/src/plugins/query_enhancements/common/utils.ts index 0d2697dc2135..2ac1cf430f5c 100644 --- a/src/plugins/query_enhancements/common/utils.ts +++ b/src/plugins/query_enhancements/common/utils.ts @@ -44,7 +44,8 @@ export const removeKeyword = (queryString: string | undefined) => { export const handleFacetError = (response: any) => { const error = new Error(response.data.body ?? response.data); - error.name = response.data.status ?? response.status; + error.name = response.data.status ?? response.status ?? response.data.statusCode; + (error as any).status = error.name; throw error; }; diff --git a/src/plugins/query_enhancements/server/search/ppl_search_strategy.ts b/src/plugins/query_enhancements/server/search/ppl_search_strategy.ts index 501e2287411b..d71ae6810fad 100644 --- a/src/plugins/query_enhancements/server/search/ppl_search_strategy.ts +++ b/src/plugins/query_enhancements/server/search/ppl_search_strategy.ts @@ -56,6 +56,7 @@ export const pplSearchStrategyProvider = ( for (const [key, aggQueryString] of Object.entries(aggConfig.qs)) { request.body.query.query = aggQueryString; const rawAggs: any = await pplFacet.describeQuery(context, request); + if (!rawAggs.success) handleFacetError(rawResponse); (dataFrame as IDataFrameWithAggs).aggs = {}; (dataFrame as IDataFrameWithAggs).aggs[key] = rawAggs.data.datarows?.map((hit: any) => { return { diff --git a/src/plugins/query_enhancements/server/utils/facet.ts b/src/plugins/query_enhancements/server/utils/facet.ts index 0b6dd52407cd..a080b8833fb7 100644 --- a/src/plugins/query_enhancements/server/utils/facet.ts +++ b/src/plugins/query_enhancements/server/utils/facet.ts @@ -100,7 +100,7 @@ export class Facet { const response = this.useJobs ? await this.fetchJobs(context, request, this.endpoint) : await this.fetch(context, request, this.endpoint); - if (!this.shimResponse) return response; + if (response.success === false || !this.shimResponse) return response; const { format: dataType } = request.body; const shimFunctions: { [key: string]: (data: any) => any } = {