diff --git a/x-pack/plugins/data_usage/server/services/autoops_api.ts b/x-pack/plugins/data_usage/server/services/autoops_api.ts index d98b0c507fe1..8f371d3004de 100644 --- a/x-pack/plugins/data_usage/server/services/autoops_api.ts +++ b/x-pack/plugins/data_usage/server/services/autoops_api.ts @@ -24,8 +24,7 @@ import { AutoOpsConfig } from '../types'; import { AutoOpsError } from './errors'; import { appContextService } from './app_context'; -const AGENT_CREATION_FAILED_ERROR = 'AutoOps API could not create the autoops agent'; -const AUTO_OPS_AGENT_CREATION_PREFIX = '[AutoOps API] Creating autoops agent failed'; +const AUTO_OPS_REQUEST_FAILED_PREFIX = '[AutoOps API] Request failed'; const AUTO_OPS_MISSING_CONFIG_ERROR = 'Missing autoops configuration'; const getAutoOpsAPIRequestUrl = (url?: string, projectId?: string): string => @@ -120,7 +119,7 @@ export class AutoOpsAPIService { (error: Error | AxiosError) => { if (!axios.isAxiosError(error)) { this.logger.error( - `${AUTO_OPS_AGENT_CREATION_PREFIX} with an error ${error} ${requestConfigDebugStatus}`, + `${AUTO_OPS_REQUEST_FAILED_PREFIX} with an error ${error}, request config: ${requestConfigDebugStatus}`, errorMetadataWithRequestConfig ); throw new AutoOpsError(withRequestIdMessage(error.message)); @@ -131,9 +130,11 @@ export class AutoOpsAPIService { if (error.response) { // The request was made and the server responded with a status code and error data this.logger.error( - `${AUTO_OPS_AGENT_CREATION_PREFIX} because the AutoOps API responded with a status code that falls out of the range of 2xx: ${JSON.stringify( + `${AUTO_OPS_REQUEST_FAILED_PREFIX} because the AutoOps API responded with a status code that falls out of the range of 2xx: ${JSON.stringify( error.response.status - )}} ${JSON.stringify(error.response.data)}} ${requestConfigDebugStatus}`, + )}} ${JSON.stringify( + error.response.data + )}}, request config: ${requestConfigDebugStatus}`, { ...errorMetadataWithRequestConfig, http: { @@ -145,22 +146,22 @@ export class AutoOpsAPIService { }, } ); - throw new AutoOpsError(withRequestIdMessage(AGENT_CREATION_FAILED_ERROR)); + throw new AutoOpsError(withRequestIdMessage(AUTO_OPS_REQUEST_FAILED_PREFIX)); } else if (error.request) { // The request was made but no response was received this.logger.error( - `${AUTO_OPS_AGENT_CREATION_PREFIX} while sending the request to the AutoOps API: ${errorLogCodeCause} ${requestConfigDebugStatus}`, + `${AUTO_OPS_REQUEST_FAILED_PREFIX} while sending the request to the AutoOps API: ${errorLogCodeCause}, request config: ${requestConfigDebugStatus}`, errorMetadataWithRequestConfig ); throw new AutoOpsError(withRequestIdMessage(`no response received from the AutoOps API`)); } else { // Something happened in setting up the request that triggered an Error this.logger.error( - `${AUTO_OPS_AGENT_CREATION_PREFIX} to be created ${errorLogCodeCause} ${requestConfigDebugStatus} ${error.toJSON()}`, + `${AUTO_OPS_REQUEST_FAILED_PREFIX} with ${errorLogCodeCause}, request config: ${requestConfigDebugStatus}, error: ${error.toJSON()}`, errorMetadataWithRequestConfig ); throw new AutoOpsError( - withRequestIdMessage(`${AGENT_CREATION_FAILED_ERROR}, ${error.message}`) + withRequestIdMessage(`${AUTO_OPS_REQUEST_FAILED_PREFIX}, ${error.message}`) ); } }