Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.14] [Obs AI Assistant] Handle Axios errors correctly (#186790) #186865

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { errors } from '@elastic/elasticsearch';
import { isAxiosError } from 'axios';
import { createFunctionResponseMessage } from '../../../common/utils/create_function_response_message';

export function createServerSideFunctionResponseError({
Expand All @@ -19,15 +20,18 @@ export function createServerSideFunctionResponseError({
}) {
const isElasticsearchError = error instanceof errors.ElasticsearchClientError;

const sanitizedError: Record<string, unknown> = JSON.parse(
'toJSON' in error && typeof error.toJSON === 'function' ? error.toJSON() : JSON.stringify(error)
);
const sanitizedError: Record<string, unknown> = JSON.parse(JSON.stringify(error));

if (isElasticsearchError) {
// remove meta key which is huge and noisy
delete sanitizedError.meta;
} else if (isAxiosError(error)) {
sanitizedError.response = { message: error.response?.data?.message };
delete sanitizedError.config;
}

delete sanitizedError.stack;

return createFunctionResponseMessage({
name,
content: {
Expand Down
Loading