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

Commit 9ef2cf55 by David Pate

Create new errors related to connections and updated the Connection Manager for …

…MySQL to utilize these errors.
1 parent cd145d24
......@@ -2,7 +2,8 @@
var AbstractConnectionManager = require('../abstract/connection-manager')
, ConnectionManager
, Utils = require('../../utils')
, Promise = require('../../promise');
, Promise = require('../../promise')
, sequelizeErrors = require('../../errors');
ConnectionManager = function(dialect, sequelize) {
AbstractConnectionManager.call(this, dialect, sequelize);
......@@ -42,16 +43,22 @@ ConnectionManager.prototype.connect = function(config) {
if (err) {
switch (err.code) {
case 'ECONNREFUSED':
reject(new sequelizeErrors.ConnectionRefusedError(err));
break;
case 'ER_ACCESS_D2ENIED_ERROR':
reject('Failed to authenticate for MySQL. Please double check your settings.');
reject(new sequelizeErrors.AccessDeniedError(err));
break;
case 'ENOTFOUND':
reject(new sequelizeErrors.HostNotFoundError(err));
break;
case 'EHOSTUNREACH':
reject(new sequelizeErrors.HostNotReachableError(err));
break;
case 'EINVAL':
reject('Failed to find MySQL server. Please double check your settings.');
reject(new sequelizeErrors.InvalidConnectionError(err));
break;
default:
reject(err);
reject(new sequelizeErrors.ConnectionError(err));
break;
}
......@@ -89,7 +96,7 @@ ConnectionManager.prototype.disconnect = function(connection) {
return new Promise(function (resolve, reject) {
connection.end(function(err) {
if (err) return reject(err);
if (err) return reject(new sequelizeErrors.ConnectionError(err));
resolve();
});
});
......
......@@ -94,6 +94,81 @@ error.DatabaseError.prototype.parent;
error.DatabaseError.prototype.sql;
/**
* A base class for all connection related errors.
* @extends BaseError
* @constructor
*/
error.ConnectionError = function (parent) {
error.BaseError.apply(this, [parent.message]);
this.name = 'SequelizeConnectionError';
this.parent = parent;
};
util.inherits(error.ConnectionError, error.BaseError);
/**
* The connection specific error which triggered this one
* @property parent
* @name parent
*/
error.ConnectionError.prototype.parent;
/**
* Thrown when a connection to a database is refused
* @extends ConnectionError
* @constructor
*/
error.ConnectionRefusedError = function (parent) {
error.ConnectionError.call(this, parent);
this.name = 'SequelizeConnectionRefusedError';
};
util.inherits(error.ConnectionRefusedError, error.ConnectionError);
/**
* Thrown when a connection to a database is refused due to insufficient privileges
* @extends ConnectionError
* @constructor
*/
error.AccessDeniedError = function (parent) {
error.AccessDeniedError.call(this, parent);
this.name = 'SequelizeAccessDeniedError';
};
util.inherits(error.AccessDeniedError, error.ConnectionError);
/**
* Thrown when a connection to a database has a hostname that was not found
* @extends ConnectionError
* @constructor
*/
error.HostNotFoundError = function (parent) {
error.HostNotFoundError.call(this, parent);
this.name = 'SequelizeHostNotFoundError';
};
util.inherits(error.HostNotFoundError, error.ConnectionError);
/**
* Thrown when a connection to a database has a hostname that was not reachable
* @extends ConnectionError
* @constructor
*/
error.HostNotReachableError = function (parent) {
error.HostNotReachableError.call(this, parent);
this.name = 'SequelizeHostNotReachableError';
};
util.inherits(error.HostNotReachableError, error.ConnectionError);
/**
* Thrown when a connection to a database has invalid values for any of the connection parameters
* @extends ConnectionError
* @constructor
*/
error.InvalidConnectionError = function (parent) {
error.InvalidConnectionError.call(this, parent);
this.name = 'SequelizeInvalidConnectionError';
};
util.inherits(error.InvalidConnectionError, error.ConnectionError);
/**
* Thrown when a database query times out because of a deadlock
* @extends DatabaseError
* @constructor
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!