diff --git a/public/components/event_analytics/explorer/query_assist/input.tsx b/public/components/event_analytics/explorer/query_assist/input.tsx index 58008819d..4e1422c99 100644 --- a/public/components/event_analytics/explorer/query_assist/input.tsx +++ b/public/components/event_analytics/explorer/query_assist/input.tsx @@ -99,7 +99,8 @@ export const QueryAssistInput: React.FC = (props) => { }, }) ); - if (explorerData.total > 0) generateSummary(); + if (explorerData.total > 0 || summaryData.responseForSummaryStatus === 'failure') + generateSummary(); })(); } }, [summaryData.responseForSummaryStatus]); diff --git a/server/routes/query_assist/routes.ts b/server/routes/query_assist/routes.ts index a9bd90348..68e1cd1bf 100644 --- a/server/routes/query_assist/routes.ts +++ b/server/routes/query_assist/routes.ts @@ -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'; @@ -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 }); } } );