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

Commit 6a05659c by David Pate

Added the connection errors to Sequelize just like the other errors. Added tests for the errors.

1 parent 1a76270e
Showing with 105 additions and 0 deletions
...@@ -320,6 +320,55 @@ module.exports = (function() { ...@@ -320,6 +320,55 @@ module.exports = (function() {
sequelizeErrors.ForeignKeyConstraintError; sequelizeErrors.ForeignKeyConstraintError;
/** /**
* A base class for all connection related errors.
* @see {Errors#ConnectionError}
*/
Sequelize.prototype.ConnectionError = Sequelize.ConnectionError =
sequelizeErrors.ConnectionError;
/**
* Thrown when a connection to a database is refused
* @see {Errors#ConnectionRefusedError}
*/
Sequelize.prototype.ConnectionRefusedError = Sequelize.ConnectionRefusedError =
sequelizeErrors.ConnectionRefusedError;
/**
* Thrown when a connection to a database is refused due to insufficient access
* @see {Errors#AccessDeniedError}
*/
Sequelize.prototype.AccessDeniedError = Sequelize.AccessDeniedError =
sequelizeErrors.AccessDeniedError;
/**
* Thrown when a connection to a database has a hostname that was not found
* @see {Errors#HostNotFoundError}
*/
Sequelize.prototype.HostNotFoundError = Sequelize.HostNotFoundError =
sequelizeErrors.HostNotFoundError;
/**
* Thrown when a connection to a database has a hostname that was not reachable
* @see {Errors#HostNotReachableError}
*/
Sequelize.prototype.HostNotReachableError = Sequelize.HostNotReachableError =
sequelizeErrors.HostNotReachableError;
/**
* Thrown when a connection to a database has invalid values for any of the connection parameters
* @see {Errors#InvalidConnectionError}
*/
Sequelize.prototype.InvalidConnectionError = Sequelize.InvalidConnectionError =
sequelizeErrors.InvalidConnectionError;
/**
* Thrown when a connection to a database times out
* @see {Errors#ConnectionTimedOutError}
*/
Sequelize.prototype.ConnectionTimedOutError = Sequelize.ConnectionTimedOutError =
sequelizeErrors.ConnectionTimedOutError;
/**
* Returns the specified dialect. * Returns the specified dialect.
* *
* @return {String} The specified dialect. * @return {String} The specified dialect.
......
...@@ -63,6 +63,62 @@ describe(Support.getTestDialectTeaser("Sequelize Errors"), function () { ...@@ -63,6 +63,62 @@ describe(Support.getTestDialectTeaser("Sequelize Errors"), function () {
expect(databaseError.name).to.equal('SequelizeDatabaseError'); expect(databaseError.name).to.equal('SequelizeDatabaseError');
expect(databaseError.message).to.equal('original database error message'); expect(databaseError.message).to.equal('original database error message');
}); });
it('ConnectionError should keep original message', function() {
var orig = new Error('original connection error message');
var connectionError = new Sequelize.ConnectionError(orig);
expect(connectionError).to.have.property('parent');
expect(connectionError.name).to.equal('SequelizeConnectionError');
expect(connectionError.message).to.equal('original connection error message');
});
it('ConnectionRefusedError should keep original message', function() {
var orig = new Error('original connection error message');
var connectionError = new Sequelize.ConnectionRefusedError(orig);
expect(connectionError).to.have.property('parent');
expect(connectionError.name).to.equal('SequelizeConnectionRefusedError');
expect(connectionError.message).to.equal('original connection error message');
});
it('AccessDeniedError should keep original message', function() {
var orig = new Error('original connection error message');
var connectionError = new Sequelize.AccessDeniedError(orig);
expect(connectionError).to.have.property('parent');
expect(connectionError.name).to.equal('SequelizeAccessDeniedError');
expect(connectionError.message).to.equal('original connection error message');
});
it('HostNotFoundError should keep original message', function() {
var orig = new Error('original connection error message');
var connectionError = new Sequelize.HostNotFoundError(orig);
expect(connectionError).to.have.property('parent');
expect(connectionError.name).to.equal('SequelizeHostNotFoundError');
expect(connectionError.message).to.equal('original connection error message');
});
it('HostNotReachableError should keep original message', function() {
var orig = new Error('original connection error message');
var connectionError = new Sequelize.HostNotReachableError(orig);
expect(connectionError).to.have.property('parent');
expect(connectionError.name).to.equal('SequelizeHostNotReachableError');
expect(connectionError.message).to.equal('original connection error message');
});
it('InvalidConnectionError should keep original message', function() {
var orig = new Error('original connection error message');
var connectionError = new Sequelize.InvalidConnectionError(orig);
expect(connectionError).to.have.property('parent');
expect(connectionError.name).to.equal('SequelizeInvalidConnectionError');
expect(connectionError.message).to.equal('original connection error message');
});
it('ConnectionTimedOutError should keep original message', function() {
var orig = new Error('original connection error message');
var connectionError = new Sequelize.ConnectionTimedOutError(orig);
expect(connectionError).to.have.property('parent');
expect(connectionError.name).to.equal('SequelizeConnectionTimedOutError');
expect(connectionError.message).to.equal('original connection 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!