import { i18n } from '@kbn/i18n' ; import { RequestHandlerWrapper } from 'kibana/server' ; export const handleDisabledApiKeysError = ( handler ) => { return async ( context , request , response ) => { try { return await handler ( context , request , response ) ; } catch ( e ) { if ( isApiKeyDisabledError ( e ) ) { return response . badRequest ( { body : new Error ( i18n . translate ( 'xpack.alerting.api.error.disabledApiKeys' , { defaultMessage : 'Alerting relies upon API keys which appear to be disabled' , } ) ) , } ) ; } throw e ; } } ; } ; export function isApiKeyDisabledError ( e ) { return e ?. message ?. includes ( 'api keys are not enabled' ) ?? false ; } export function isSecurityPluginDisabledError ( e ) { return e ?. message ?. includes ( 'no handler found' ) ?? false ; }