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

Commit 79a9c326 by Roman Shtylman

keep original error message when wrapping in DatabaseError

fixes #2521
1 parent c6982f2c
Showing with 9 additions and 1 deletions
...@@ -72,7 +72,7 @@ error.ValidationError.prototype.errors; ...@@ -72,7 +72,7 @@ error.ValidationError.prototype.errors;
* @constructor * @constructor
*/ */
error.DatabaseError = function (parent) { error.DatabaseError = function (parent) {
error.BaseError.apply(this, arguments); error.BaseError.apply(this, [parent.message]);
this.name = 'SequelizeDatabaseError'; this.name = 'SequelizeDatabaseError';
this.parent = parent; this.parent = parent;
......
...@@ -55,6 +55,14 @@ describe(Support.getTestDialectTeaser("Sequelize Errors"), function () { ...@@ -55,6 +55,14 @@ describe(Support.getTestDialectTeaser("Sequelize Errors"), function () {
expect(matches).to.have.lengthOf(1); expect(matches).to.have.lengthOf(1);
expect(matches[0]).to.have.property('message', 'invalid'); expect(matches[0]).to.have.property('message', 'invalid');
}); });
it('SequelizeDatabaseError should keep original message', function() {
var orig = new Error('original database error message');
var databaseError = new Sequelize.DatabaseError(orig);
expect(databaseError).to.have.property('parent');
expect(databaseError.name).to.equal('SequelizeDatabaseError');
expect(databaseError.message).to.equal('original database error message');
});
}); });
describe('Constraint error', function () { describe('Constraint error', function () {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!