不要怂,就是干,撸起袖子干!

Commit 8640abe3 by Sushant

added new error class EmptyResultError for rejectOnEmpty

1 parent 163651b2
...@@ -299,3 +299,15 @@ error.InstanceError = function (message) { ...@@ -299,3 +299,15 @@ error.InstanceError = function (message) {
this.message = message; this.message = message;
}; };
util.inherits(error.InstanceError, error.BaseError); util.inherits(error.InstanceError, error.BaseError);
/**
* Thrown when a record was not found, Usually used with kenophobic mode (see message for details)
* @extends BaseError
* @constructor
*/
error.EmptyResultError = function (message) {
error.BaseError.apply(this, arguments);
this.name = 'SequelizeEmptyResultError';
this.message = message;
};
util.inherits(error.EmptyResultError, error.BaseError);
...@@ -441,6 +441,13 @@ Sequelize.prototype.ConnectionTimedOutError = Sequelize.ConnectionTimedOutError ...@@ -441,6 +441,13 @@ Sequelize.prototype.ConnectionTimedOutError = Sequelize.ConnectionTimedOutError
Sequelize.prototype.InstanceError = Sequelize.InstanceError = Sequelize.prototype.InstanceError = Sequelize.InstanceError =
sequelizeErrors.InstanceError; sequelizeErrors.InstanceError;
/**
* Thrown when a record was not found, Usually used with kenophobic mode (see message for details)
* @see {Errors#RecordNotFoundError}
*/
Sequelize.prototype.EmptyResultError = Sequelize.EmptyResultError =
sequelizeErrors.EmptyResultError;
Sequelize.prototype.refreshTypes = function () { Sequelize.prototype.refreshTypes = function () {
this.connectionManager.refreshTypeParser(DataTypes); this.connectionManager.refreshTypeParser(DataTypes);
......
...@@ -944,13 +944,13 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -944,13 +944,13 @@ describe(Support.getTestDialectTeaser('Model'), function() {
} }
}, { }, {
kenophobic: true kenophobic: true
})).to.eventually.be.rejectedWith(Sequelize.RecordNotFoundError); })).to.eventually.be.rejectedWith(Sequelize.EmptyResultError);
}); });
it('throws error when record not found by findById', function() { it('throws error when record not found by findById', function() {
return expect(this.User.findById(4732322332323333232344334354234, { return expect(this.User.findById(4732322332323333232344334354234, {
kenophobic: true kenophobic: true
})).to.eventually.be.rejectedWith(Sequelize.RecordNotFoundError); })).to.eventually.be.rejectedWith(Sequelize.EmptyResultError);
}); });
it('throws error when record not found by find', function() { it('throws error when record not found by find', function() {
...@@ -960,7 +960,7 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -960,7 +960,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
} }
}, { }, {
kenophobic: true kenophobic: true
})).to.eventually.be.rejectedWith(Sequelize.RecordNotFoundError); })).to.eventually.be.rejectedWith(Sequelize.EmptyResultError);
}); });
}); });
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!