Skip to content

Commit

Permalink
(query assist) extract ppl from error response
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Li <[email protected]>
  • Loading branch information
joshuali925 committed Jan 19, 2024
1 parent 8f1f83a commit a5824bd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ export const QueryAssistInput: React.FC<Props> = (props) => {
},
})
);
if (explorerData.total > 0) generateSummary();
if (explorerData.total > 0 || summaryData.responseForSummaryStatus === 'failure')
generateSummary();
})();
}
}, [summaryData.responseForSummaryStatus]);
Expand Down
12 changes: 8 additions & 4 deletions server/routes/query_assist/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
IRouter,
ResponseError,
} from '../../../../../src/core/server';
import { isResponseError } from '../../../../../src/core/server/opensearch/client/errors';
import { QUERY_ASSIST_API } from '../../../common/constants/query_assist';
import { generateFieldContext } from '../../common/helpers/query_assist/generate_field_context';
import { requestWithRetryAgentSearch } from './utils/agents';
Expand Down Expand Up @@ -69,10 +70,13 @@ export function registerQueryAssistRoutes(router: IRouter, config: Observability
.replace(/\bSPAN\(/g, 'span('); // https://github.com/opensearch-project/dashboards-observability/issues/759
return response.ok({ body: ppl });
} catch (error) {
return response.custom({
statusCode: error.statusCode || 500,
body: error.message,
});
// parse PPL query from error response if exists
// TODO remove after https://github.com/opensearch-project/skills/issues/138
if (isResponseError(error) && error.body.error?.reason) {
const pplMatch = error.body.error.reason.match(/execute ppl:(.+), get error:/);
if (pplMatch[1]) return response.ok({ body: pplMatch[1] });
}
return response.custom({ statusCode: error.statusCode || 500, body: error.message });
}
}
);
Expand Down

0 comments on commit a5824bd

Please sign in to comment.