Skip to content

Commit

Permalink
[Discover] fix error handling in query enhancement facet (opensearch-…
Browse files Browse the repository at this point in the history
…project#8743)

* [Discover] fix error handling in query enhancement facet

---------

Signed-off-by: Joshua Li <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and Qxisylolo committed Oct 30, 2024
1 parent 2002e79 commit d16d8a7
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/8743.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- Fix error handling in query enhancement facet ([#8743](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8743))
3 changes: 2 additions & 1 deletion src/plugins/query_enhancements/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/query_enhancements/server/utils/facet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } = {
Expand Down

0 comments on commit d16d8a7

Please sign in to comment.