Skip to content

Commit

Permalink
[Discover] fix error handling in query enhancement facet (#8743)
Browse files Browse the repository at this point in the history
* [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
1 parent 48bfe2c commit 2f31914
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 2f31914

Please sign in to comment.