import { kibanaResponseFactory } from '../../../../../../src/core/server' ; import { AccessForbidden , CannotCreateIndex , IndexNotFound , MultipleReindexJobsFound , ReindexAlreadyInProgress , ReindexCannotBeCancelled , ReindexTaskCannotBeDeleted , ReindexTaskFailed , } from '../../lib/reindexing/error_symbols' ; import { ReindexError } from '../../lib/reindexing/error' ; export const mapAnyErrorToKibanaHttpResponse = ( e ) => { if ( e instanceof ReindexError ) { switch ( e . symbol ) { case AccessForbidden : return kibanaResponseFactory . forbidden ( { body : e . message } ) ; case IndexNotFound : return kibanaResponseFactory . notFound ( { body : e . message } ) ; case CannotCreateIndex : case ReindexTaskCannotBeDeleted : throw e ; case ReindexTaskFailed : return kibanaResponseFactory . customError ( { body : e . message , statusCode : 422 } ) ; case ReindexAlreadyInProgress : case MultipleReindexJobsFound : case ReindexCannotBeCancelled : return kibanaResponseFactory . badRequest ( { body : e . message } ) ; default : } } throw e ; } ;