import { isBoom } from '@hapi/boom' ; import { schema } from '@kbn/config-schema' ; import { getFields } from '../lib/get_fields' ; import { Framework } from '../plugin' ; import { ROUTES } from '../../common/constants' ; import { VisTypeTimeseriesRouter } from '../types' ; export const fieldsRoutes = ( router , framework ) => { router . get < { } , { index : string ; } , { } > ( { path : ROUTES . FIELDS , validate : { query : schema . object ( { index : schema . string ( ) } ) , } , } , async ( context , req , res ) => { try { return res . ok ( { body : await getFields ( context , req , framework , req . query . index ) } ) ; } catch ( err ) { if ( isBoom ( err ) && err . output . statusCode === 401 ) { return res . customError ( { body : err . output . payload , statusCode : err . output . statusCode , headers : err . output . headers as { [ key ] : string ; } , } ) ; } return res . ok ( { body : [ ] , } ) ; } } ) ; } ;