function errorsReducer(state = [], action) {
  switch (action.type) {
    case LOGIN_ERROR:
    case UNAUTHORIZED_ERROR:
      if (!Array.isArray(state)) {
        throw new Error('Errors state must be an array')
      }
      return [...state, action.authError]
    case LOGOUT:
    case CLEAR_ERRORS:
      // Support keeping errors through a filter function
      if (action.preserve && action.preserve.errors) {
        if (typeof action.preserve.errors !== 'function') {
          throw new Error(
            'Preserve for the errors state currently only supports functions'
          )
        }
        return state.filter(action.preserve.errors) // run filter function on state
      }
      return []
    default:
      return state
  }
}
Reducer for errors state. Changed by `UNAUTHORIZED_ERROR`, `CLEAR_ERRORS`,
and `LOGOUT` actions.
@param  {object} [state=[]] - Current errors redux state
@param  {object} action - Object containing the action that was dispatched
@param  {string} action.type - Type of action that was dispatched
@param  {Function} action.preserve - `not required` Filter function for
preserving errors
@returns {object} Profile state after reduction