Skip to content

Commit

Permalink
Add PasswordMismatchError to bookshelf itself
Browse files Browse the repository at this point in the history
  • Loading branch information
venables committed Feb 13, 2017
1 parent 23afa8a commit f0d22e3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class PasswordMismatchError extends Error {
constructor (message) {
super(message)
super(message || 'Invalid password')
this.name = 'PasswordMismatchError'
}
}
Expand Down
6 changes: 4 additions & 2 deletions lib/secure-password.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ module.exports = function (Bookshelf) {
const PasswordMismatchError = require('./error')
const proto = Bookshelf.Model.prototype

Bookshelf.PasswordMismatchError = PasswordMismatchError
Bookshelf.Model.PasswordMismatchError = PasswordMismatchError
Bookshelf.plugin('virtuals')

/**
Expand Down Expand Up @@ -80,13 +82,13 @@ module.exports = function (Bookshelf) {
.compare(password, this.get(passwordField(this)))
.then((matches) => {
if (!matches) {
throw new PasswordMismatchError()
throw new this.constructor.PasswordMismatchError()
}

return this
})
.catch(() => {
throw new PasswordMismatchError()
throw new this.constructor.PasswordMismatchError()
})
}
})
Expand Down

0 comments on commit f0d22e3

Please sign in to comment.