New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find returns a null instance instead of catch #5480

Closed
KieronWiltshire opened this Issue Feb 24, 2016 · 1 comment

Comments

2 participants
@KieronWiltshire

KieronWiltshire commented Feb 24, 2016

So this is my section of code:

  /**
   * Verifies the specified user against the specified token
   * @param {string | number} user
   * @param {string} token
   * @returns {Object} promise
   */
  static verifyEmailVerificationToken(user, token) {
    return models.User.findOne({where: {$or: [{email: user}, {id: user}], emailToken: token}}).then(function(user) {
      return user.update({emailConfirmed: true, emailToken: null}).then(function(user) {
        eventService.emit('users.verifyEmailVerificationToken', user);
        return user;
      });
    });
  }

The user.update section should not be fired am I correct? The promise's "catch" callback should be the code that is triggered, however it is not. The "then" callback is being called with a null instance.

now I know this is the intended purpose, but shouldn't it invoke the catch instead?

@janmeier

This comment has been minimized.

Member

janmeier commented Feb 24, 2016

Do you want for findOne to throw an error when nothing is found? In that case, see #272

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment