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

Commit 9c7500d7 by Brian Romanko

Fixing the error object inheritence

1 parent 2bb1845c
Showing with 31 additions and 17 deletions
......@@ -4,7 +4,6 @@
* @fileOverview The Error Objects produced by Sequelize.
*/
var util = require('util');
var error = module.exports = {};
/**
......@@ -13,9 +12,17 @@ var error = module.exports = {};
* @constructor
*/
error.BaseError = function() {
Error.apply(this, arguments);
var tmp = Error.apply(this, arguments);
tmp.name = this.name = 'SequelizeBaseError';
this.stack = tmp.stack;
this.message = tmp.message;
return this;
};
util.inherits(error.BaseError, Error);
error.BaseError.prototype = Object.create(Error.prototype, {
constructor: { value: error.BaseError }
});
/**
......@@ -25,5 +32,10 @@ util.inherits(error.BaseError, Error);
*/
error.ValidationError = function() {
error.BaseError.apply(this, arguments);
this.name = 'SequelizeValidationError';
return this;
};
util.inherits(error.ValidationError, error.BaseError);
error.ValidationError.prototype = Object.create(error.BaseError.prototype, {
constructor: { value: error.ValidationError }
});
\ No newline at end of file
......@@ -2,20 +2,19 @@
var chai = require('chai')
, expect = chai.expect
, Support = require(__dirname + '/support')
, Sequelize = Support.Sequelize
// , sinon = require('sinon')
, Sequelize = Support.Sequelize;
chai.config.includeStack = true
chai.config.includeStack = true;
describe(Support.getTestDialectTeaser("Sequelize Errors"), function () {
describe('API Surface', function() {
it('Should have the Error constructors exposed', function() {
expect(Sequelize).to.have.property('Error')
expect(Sequelize).to.have.property('ValidationError')
expect(Sequelize).to.have.property('Error');
expect(Sequelize).to.have.property('ValidationError');
var sequelize = new Sequelize();
expect(sequelize).to.have.property('Error')
expect(sequelize).to.have.property('ValidationError')
})
expect(sequelize).to.have.property('Error');
expect(sequelize).to.have.property('ValidationError');
});
it('Sequelize Errors instances should be instances of Error', function() {
var error = new Sequelize.Error();
var validationError = new Sequelize.ValidationError();
......@@ -25,10 +24,12 @@ describe(Support.getTestDialectTeaser("Sequelize Errors"), function () {
var instError = new sequelize.Error();
var instValidationError = new sequelize.ValidationError();
expect(error).to.be.instanceOf(Error)
expect(validationError).to.be.instanceOf(Error)
expect(instError).to.be.instanceOf(Error)
expect(instValidationError).to.be.instanceOf(Error)
expect(error).to.be.instanceOf(Sequelize.Error);
expect(error).to.have.property('name', 'SequelizeBaseError');
expect(validationError).to.be.instanceOf(Sequelize.ValidationError);
expect(validationError).to.have.property('name', 'SequelizeValidationError');
expect(instError).to.be.instanceOf(Sequelize.Error);
expect(instValidationError).to.be.instanceOf(Sequelize.ValidationError);
})
})
})
});
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!