Skip to content

Commit

Permalink
馃悰 Fix error message for login when password wrong (#8594)
Browse files Browse the repository at this point in the history
closes #8565

- isPasswordCorrect fn returns a specific error, which we simply forward
- no need to wrap a custom error into a new custom error
- the rule is always: if you are using a Ghost unit/function, you can expect that this unit returns a custom error
  • Loading branch information
aileen authored and kirrg001 committed Jun 19, 2017
1 parent bc30146 commit 35bd0ae
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
7 changes: 2 additions & 5 deletions core/server/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,11 +673,7 @@ User = ghostBookshelf.Model.extend({
});
})
.catch(function onError(err) {
return Promise.reject(new errors.UnauthorizedError({
err: err,
context: i18n.t('errors.models.user.incorrectPassword'),
help: i18n.t('errors.models.user.userUpdateError.help')
}));
return Promise.reject(err);
});
}, function handleError(error) {
if (error.message === 'NotFound' || error.message === 'EmptyResponse') {
Expand Down Expand Up @@ -705,6 +701,7 @@ User = ghostBookshelf.Model.extend({
}

return Promise.reject(new errors.ValidationError({
context: i18n.t('errors.models.user.incorrectPassword'),
message: i18n.t('errors.models.user.incorrectPassword'),
help: i18n.t('errors.models.user.userUpdateError.help'),
code: 'PASSWORD_INCORRECT'
Expand Down
4 changes: 2 additions & 2 deletions core/test/functional/routes/api/authentication_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ describe('Authentication API', function () {
client_secret: 'not_available'
}).expect('Content-Type', /json/)
.expect('Cache-Control', testUtils.cacheRules.private)
.expect(401)
.expect(422)
.end(function (err, res) {
if (err) {
return done(err);
}
var jsonResponse = res.body;
should.exist(jsonResponse.errors[0].errorType);
jsonResponse.errors[0].errorType.should.eql('UnauthorizedError');
jsonResponse.errors[0].errorType.should.eql('ValidationError');
done();
});
});
Expand Down
6 changes: 3 additions & 3 deletions core/test/functional/routes/api/spam_prevention_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe('Spam Prevention API', function () {
client_secret: 'not_available'
})
.expect('Content-Type', /json/)
.expect(401)
.expect(422)
.end(function (err) {
if (err) {
return done(err);
Expand Down Expand Up @@ -155,7 +155,7 @@ describe('Spam Prevention API', function () {
client_id: 'ghost-admin',
client_secret: 'not_available'
}).expect('Content-Type', /json/)
.expect(401)
.expect(422)
.end(function (err) {
if (err) {
return done(err);
Expand Down Expand Up @@ -220,7 +220,7 @@ describe('Spam Prevention API', function () {
client_id: 'ghost-admin',
client_secret: 'not_available'
}).expect('Content-Type', /json/)
.expect(401)
.expect(422)
.end(function (err) {
if (err) {
return done(err);
Expand Down
2 changes: 1 addition & 1 deletion core/test/integration/model/model_users_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ describe('User Model', function run() {
return UserModel.check(object).then(userWasLoggedIn)
.catch(function checkError(error) {
should.exist(error);
error.errorType.should.equal('UnauthorizedError');
error.errorType.should.equal('ValidationError');
});
});
});
Expand Down

0 comments on commit 35bd0ae

Please sign in to comment.