function createProfileWatchErrorHandler(dispatch, firebase) {
  const {
    config: { onProfileListenerError, logErrors }
  } = firebase._
  return function handleProfileError(err) {
    if (logErrors) {
      // eslint-disable-next-line no-console
      console.error(`Error with profile listener: ${err.message || ''}`, err)
    }
    if (typeof onProfileListenerError === 'function') {
      const factoryResult = onProfileListenerError(err, firebase)
      // Return factoryResult if it is a promise
      if (typeof factoryResult.then === 'function') {
        return factoryResult
      }
    }
    return Promise.reject(err)
  }
}
Creates a function for handling errors from profile watcher. Used for
both RTDB and Firestore.
@param {Function} dispatch - Action dispatch function
@param {object} firebase - Internal firebase object
@returns {Function} Profile watch error handler function
@private