diff --git a/src/core/packages/root/server-internal/src/bootstrap.ts b/src/core/packages/root/server-internal/src/bootstrap.ts index 0e91f368dc448..6327db1a71fe5 100644 --- a/src/core/packages/root/server-internal/src/bootstrap.ts +++ b/src/core/packages/root/server-internal/src/bootstrap.ts @@ -129,17 +129,17 @@ export async function bootstrap({ configs, cliArgs, applyConfigOverrides }: Boot } } -function onRootShutdown(reason?: any) { - if (reason !== undefined) { - if (reason.code !== MIGRATION_EXCEPTION_CODE) { +function onRootShutdown(error?: any) { + if (error !== undefined) { + if (error.code !== MIGRATION_EXCEPTION_CODE) { // There is a chance that logger wasn't configured properly and error that // that forced root to shut down could go unnoticed. To prevent this we always // mirror such fatal errors in standard output with `console.error`. // eslint-disable-next-line no-console - console.error(`\n${chalk.white.bgRed(' FATAL ')} ${reason}\n`); + console.error(`\n${chalk.white.bgRed(' FATAL ')} ${error}\n`); } - process.exit(reason instanceof CriticalError ? reason.processExitCode : 1); + process.exit(error instanceof CriticalError ? error.processExitCode : 1); } process.exit(0); diff --git a/src/core/packages/saved-objects/api-server-internal/src/lib/utils/decorate_es_error.ts b/src/core/packages/saved-objects/api-server-internal/src/lib/utils/decorate_es_error.ts index 1e32faafbba9f..3b336fa774850 100644 --- a/src/core/packages/saved-objects/api-server-internal/src/lib/utils/decorate_es_error.ts +++ b/src/core/packages/saved-objects/api-server-internal/src/lib/utils/decorate_es_error.ts @@ -9,6 +9,7 @@ import { get } from 'lodash'; import { errors as esErrors } from '@elastic/elasticsearch'; +import type { ErrorCause } from '@elastic/elasticsearch/lib/api/types'; import type { ElasticsearchErrorDetails } from '@kbn/es-errors'; import { isSupportedEsServer } from '@kbn/core-elasticsearch-server-internal'; import { SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-server'; @@ -38,7 +39,10 @@ export function decorateEsError(error: EsErrors) { throw new Error('Expected an instance of Error'); } - const { reason } = get(error, 'body.error', { reason: undefined }) as { reason?: string }; + const { reason: esErrorReason } = get(error, 'body.error', { + reason: undefined, + }) as ErrorCause; + const reason = esErrorReason || undefined; if ( error instanceof ConnectionError || error instanceof NoLivingConnectionsError ||