Skip to content

Commit

Permalink
[query assist] update ml-commons response schema (#2124) (#2130)
Browse files Browse the repository at this point in the history
(cherry picked from commit acff04b)

Signed-off-by: Joshua Li <joshuali925@gmail.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 5812d26 commit 7c5c96a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
7 changes: 6 additions & 1 deletion server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ export function setupRoutes({
registerIntegrationsRoute(router);
registerDataConnectionsRoute(router, dataSourceEnabled);
registerDatasourcesRoute(router, dataSourceEnabled);
registerQueryAssistRoutes(router);

// query assist is part of log explorer, which will be disabled if datasource is enabled
if (!dataSourceEnabled) {
registerQueryAssistRoutes(router);
}

registerGettingStartedRoutes(router);
}
16 changes: 12 additions & 4 deletions server/routes/query_assist/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,15 @@ export function registerQueryAssistRoutes(router: IRouter) {
if (
isResponseError(error) &&
error.statusCode === 400 &&
error.body.includes(ERROR_DETAILS.GUARDRAILS_TRIGGERED)
// on opensearch >= 2.17, error.body is an object https://github.com/opensearch-project/ml-commons/pull/2858
JSON.stringify(error.body).includes(ERROR_DETAILS.GUARDRAILS_TRIGGERED)
) {
return response.badRequest({ body: ERROR_DETAILS.GUARDRAILS_TRIGGERED });
}
return response.custom({ statusCode: error.statusCode || 500, body: error.message });
return response.custom({
statusCode: error.statusCode || 500,
body: typeof error.body === 'string' ? error.body : JSON.stringify(error.body),
});
}
}
);
Expand Down Expand Up @@ -155,11 +159,15 @@ export function registerQueryAssistRoutes(router: IRouter) {
if (
isResponseError(error) &&
error.statusCode === 400 &&
error.body.includes(ERROR_DETAILS.GUARDRAILS_TRIGGERED)
// on opensearch >= 2.17, error.body is an object https://github.com/opensearch-project/ml-commons/pull/2858
JSON.stringify(error.body).includes(ERROR_DETAILS.GUARDRAILS_TRIGGERED)
) {
return response.badRequest({ body: ERROR_DETAILS.GUARDRAILS_TRIGGERED });
}
return response.custom({ statusCode: error.statusCode || 500, body: error.message });
return response.custom({
statusCode: error.statusCode || 500,
body: typeof error.body === 'string' ? error.body : JSON.stringify(error.body),
});
}
}
);
Expand Down

0 comments on commit 7c5c96a

Please sign in to comment.