77import Boom from 'boom' ;
88import { schema } from '@kbn/config-schema' ;
99import { ILegacyScopedClusterClient , SavedObject , RequestHandlerContext } from 'src/core/server' ;
10- import { CoreSetup } from 'src/core/server' ;
10+ import { CoreSetup , Logger } from 'src/core/server' ;
1111import { BASE_API_URL } from '../../common' ;
1212import { IndexPatternAttributes , UI_SETTINGS } from '../../../../../src/plugins/data/server' ;
1313
14+ export function isBoomError ( error : { isBoom ?: boolean } ) : error is Boom {
15+ return error . isBoom === true ;
16+ }
17+
1418/**
1519 * The number of docs to sample to determine field empty status.
1620 */
@@ -24,7 +28,7 @@ export interface Field {
2428 script ?: string ;
2529}
2630
27- export async function existingFieldsRoute ( setup : CoreSetup ) {
31+ export async function existingFieldsRoute ( setup : CoreSetup , logger : Logger ) {
2832 const router = setup . http . createRouter ( ) ;
2933
3034 router . post (
@@ -52,14 +56,17 @@ export async function existingFieldsRoute(setup: CoreSetup) {
5256 } ) ,
5357 } ) ;
5458 } catch ( e ) {
59+ logger . info (
60+ `Field existence check failed: ${ isBoomError ( e ) ? e . output . payload . message : e . message } `
61+ ) ;
5562 if ( e . status === 404 ) {
56- return res . notFound ( ) ;
63+ return res . notFound ( { body : e . message } ) ;
5764 }
58- if ( e . isBoom ) {
65+ if ( isBoomError ( e ) ) {
5966 if ( e . output . statusCode === 404 ) {
60- return res . notFound ( ) ;
67+ return res . notFound ( { body : e . output . payload . message } ) ;
6168 }
62- return res . internalError ( e . output . message ) ;
69+ return res . internalError ( { body : e . output . payload . message } ) ;
6370 } else {
6471 return res . internalError ( {
6572 body : Boom . internal ( e . message || e . name ) ,
0 commit comments