diff --git a/.eslintrc.js b/.eslintrc.js index cd6869769bf67..d95536cc484bb 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -416,7 +416,6 @@ const AXIOS_LEGACY_CONSUMERS = [ 'src/platform/packages/shared/kbn-kbn-client/**/*.{js,mjs,ts,tsx}', 'src/platform/packages/shared/kbn-test-saml-auth/**/*.{js,mjs,ts,tsx}', 'src/platform/plugins/shared/workflows_execution_engine/server/step/http_step/**/*.{js,mjs,ts,tsx}', - 'src/platform/plugins/shared/workflows_management/server/connectors/workflows/**/*.{js,mjs,ts,tsx}', 'src/platform/test/api_integration/apis/telemetry/**/*.{js,mjs,ts,tsx}', 'x-pack/examples/alerting_example/server/rule_types/**/*.{js,mjs,ts,tsx}', 'x-pack/packages/kbn-synthetics-private-location/**/*.{js,mjs,ts,tsx}', diff --git a/src/platform/plugins/shared/workflows_management/server/connectors/workflows/utils.test.ts b/src/platform/plugins/shared/workflows_management/server/connectors/workflows/utils.test.ts index 042ca6874b762..6e1da1a7c4715 100644 --- a/src/platform/plugins/shared/workflows_management/server/connectors/workflows/utils.test.ts +++ b/src/platform/plugins/shared/workflows_management/server/connectors/workflows/utils.test.ts @@ -7,48 +7,47 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import type { AxiosError } from 'axios'; import { createServiceError } from './utils'; describe('Workflows Utils', () => { describe('createServiceError', () => { - it('should create error with Axios error message', () => { - const axiosError = { - isAxiosError: true, + it('should create error with HTTP error message', () => { + const httpError = { + name: 'Error', response: { data: { message: 'API Error: Invalid request', }, }, message: 'Request failed', - } as AxiosError; + } as Error; - const result = createServiceError(axiosError, 'Operation failed'); + const result = createServiceError(httpError, 'Operation failed'); expect(result.message).toBe('Operation failed. Error: API Error: Invalid request'); }); - it('should use Axios error message when response data has no message', () => { - const axiosError = { - isAxiosError: true, + it('should use HTTP error message when response data has no message', () => { + const httpError = { + name: 'Error', response: { data: {}, }, message: 'Network error', - } as AxiosError; + } as Error; - const result = createServiceError(axiosError, 'Operation failed'); + const result = createServiceError(httpError, 'Operation failed'); expect(result.message).toBe('Operation failed. Error: Network error'); }); - it('should handle Axios error without response data', () => { - const axiosError = { - isAxiosError: true, + it('should handle HTTP error without response data', () => { + const httpError = { + name: 'Error', message: 'Connection timeout', - } as AxiosError; + } as Error; - const result = createServiceError(axiosError, 'Operation failed'); + const result = createServiceError(httpError, 'Operation failed'); expect(result.message).toBe('Operation failed. Error: Connection timeout'); }); diff --git a/src/platform/plugins/shared/workflows_management/server/connectors/workflows/utils.ts b/src/platform/plugins/shared/workflows_management/server/connectors/workflows/utils.ts index d9c9e017fd8d9..35dd1070350b3 100644 --- a/src/platform/plugins/shared/workflows_management/server/connectors/workflows/utils.ts +++ b/src/platform/plugins/shared/workflows_management/server/connectors/workflows/utils.ts @@ -7,14 +7,10 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import { isAxiosError } from 'axios'; - export const createServiceError = (error: Error, message: string) => { - if (isAxiosError(error)) { - const responseData = error.response?.data; - const errorMessage = responseData?.message || error.message; - return new Error(`${message}. Error: ${errorMessage}`); - } - - return new Error(`${message}. Error: ${error.message}`); + // Some HTTP clients attach the parsed response body on `error.response.data`; + // prefer the upstream `message` field if it is present. + const responseData = (error as { response?: { data?: { message?: string } } }).response?.data; + const errorMessage = responseData?.message || error.message; + return new Error(`${message}. Error: ${errorMessage}`); };