import { Store } from 'vuex' ; import { RootStore } from '@/store/types' ; interface ErrorResponse { message : string ; response ? : { data : string ; status : number ; } ; } type ApiError = ErrorResponse | string ; export const errorMessage = ( err ) : string => { if ( typeof err === 'string' ) { return err ; } if ( err . response && err . response . status === 404 ) { return '404 not found' ; } return ( err . response && err . response . data ) || err . message ; } ; export const showSystemMessage = ( store , text , type , duration ? ) => { store . commit ( 'message/showMessage' , { text , class : type , duration } ) ; } ; export const clearSystemMessage = ( store ) => { store . commit ( 'message/closeMessage' ) ; } ; /** Displays an error message using the system message popup. */ export const systemMessageErrorHandler = ( store ) => { return ( err ) => { if ( err . stack ) { throw err ; return ; } showSystemMessage ( store , errorMessage ( err ) , 'error' ) ; } ; } ;