import { boomify , isBoom } from '@hapi/boom' ; import { ResponseError , CustomHttpResponseOptions } from 'kibana/server' ; export function wrapError ( error ) { const boom = isBoom ( error ) ? error : boomify ( error , { statusCode : error . status ?? error . statusCode } ) ; const statusCode = boom . output . statusCode ; return { body : { message : boom , ... ( statusCode !== 500 && error . body ? { attributes : { body : error . body } } : { } ) , } , headers : boom . output . headers as { [ key ] : string ; } , statusCode , } ; }