import { IHttpFetchError } from 'kibana/public' ; import { toasts , fatalError } from './notification' ; interface CommonErrorBody { statusCode : number ; message : string ; error : string ; } function createToastConfig ( error , errorTitle ) { if ( error && error . body ) { const { error : errorString , statusCode , message } = error . body ; return { title : errorTitle , text : `${ statusCode }: ${ errorString }. ${ message }` , } ; } } export function showApiWarning ( error , errorTitle ) { const toastConfig = createToastConfig ( error , errorTitle ) ; if ( toastConfig ) { return toasts . addWarning ( toastConfig ) ; } return fatalError . add ( error , errorTitle ) ; } export function showApiError ( error , errorTitle ) { const toastConfig = createToastConfig ( error , errorTitle ) ; if ( toastConfig ) { return toasts . addDanger ( toastConfig ) ; } fatalError . add ( error , errorTitle ) ; }