Skip to content

Commit

Permalink
[query assist] update ml-commons response schema processing
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Li <[email protected]>
  • Loading branch information
joshuali925 committed Sep 4, 2024
1 parent 744a039 commit f9399ff
Showing 1 changed file with 12 additions and 4 deletions.
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 f9399ff

Please sign in to comment.