export const CLEAR_ALL_ERRORS = 'CLEAR_ALL_ERRORS' ; const errorsReducer = ( state = { } , action ) => { const { type , payload } = action ; if ( type === CLEAR_ALL_ERRORS ) return { } ; const matches = /(.*)_(REQUEST|FAILURE)/ . exec ( type ) ; if ( ! matches ) return state ; const [ , requestName , requestState ] = matches ; return { ... state , [ requestName ] : requestState === 'FAILURE' ? payload : '' , } ; } ; export default errorsReducer ;