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

Commit 5815b783 by Mick Hansen

Merge pull request #1360 from thanpolas/expose-Validatior-Error

introduce the Sequelize signed Error Objects
2 parents d2c55120 e71efc6b
var Validator = require("validator")
, Utils = require("./utils")
, sequelizeError = require("./errors")
var DaoValidator = module.exports = function(model, options) {
options = options || {}
......@@ -27,7 +28,7 @@ DaoValidator.prototype.validate = function() {
emitter.emit('success')
})
.error(function(err) {
var error = new Error('Validation error')
var error = new sequelizeError.ValidationError('Validation error')
error[DaoValidator.RAW_KEY_NAME] = []
Utils._.each(err, function (value) {
......
/**
* @fileOverview The Error Objects produced by Sequelize.
*/
var util = require('util')
var error = module.exports = {}
/**
* The Base Error all Sequelize Errors inherit from.
*
* @constructor
*/
error.BaseError = function() {
Error.call(this)
};
util.inherits(error.BaseError, Error)
/**
* Validation Error
*
* @constructor
*/
error.ValidationError = function() {
error.BaseError.call(this)
};
util.inherits(error.ValidationError, error.BaseError)
......@@ -8,6 +8,7 @@ var url = require("url")
, Transaction = require("./transaction")
, TransactionManager = require('./transaction-manager')
, QueryTypes = require('./query-types')
, sequelizeErrors = require('./errors')
module.exports = (function() {
/**
......@@ -150,6 +151,15 @@ module.exports = (function() {
})
/**
* Expose Sequelize Error types
*/
Sequelize.prototype.Error = Sequelize.Error =
sequelizeErrors.BaseError
Sequelize.prototype.ValidationError = Sequelize.ValidationError =
sequelizeErrors.ValidationError
/**
* Returns the specified dialect.
*
* @return {String} The specified dialect.
......
/* jshint camelcase: false */
var chai = require('chai')
, expect = chai.expect
, Support = require(__dirname + '/support')
, Sequelize = Support.Sequelize
// , sinon = require('sinon')
chai.Assertion.includeStack = true
describe.only(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')
var sequelize = new Sequelize();
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();
var sequelize = new Sequelize();
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)
})
})
})
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!