import { IHttpFetchError , ResponseErrorBody } from 'src/core/public' ; import { fatalErrors , toasts } from './notification' ; interface CommonErrorBody extends ResponseErrorBody { error : string ; attributes : { causes : unknown [ ] ; } ; } function createToastConfig ( error , errorTitle ) { if ( error && error . body ) { const { error : errorString , statusCode , message : errorMessage , attributes } = error . body ; const message = attributes ?. causes ?. length ? attributes . causes [ attributes . causes . length - 1 ] : errorMessage ; return { title : errorTitle , text : `${ statusCode }: ${ errorString }. ${ message }` , } ; } } export function showApiWarning ( error , errorTitle ) { const toastConfig = createToastConfig ( error , errorTitle ) ; if ( toastConfig ) { return toasts . addWarning ( toastConfig ) ; } return fatalErrors . add ( error , errorTitle ) ; } export function showApiError ( error , errorTitle ) { const toastConfig = createToastConfig ( error , errorTitle ) ; if ( toastConfig ) { return toasts . addDanger ( toastConfig ) ; } fatalErrors . add ( error , errorTitle ) ; }