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 } = {