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

Commit 6e0cf9d6 by David Pate

Added an error for connections timing out. Updated Postgres connection manager t…

…o use the new errors.
1 parent ffc35bb1
......@@ -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);
......@@ -56,19 +57,23 @@ ConnectionManager.prototype.connect = function(config) {
if (err.code) {
switch (err.code) {
case 'ECONNREFUSED':
reject(new Error('Failed to authenticate for PostgresSQL. Please double check your settings.'));
reject(new sequelizeErrors.ConnectionRefusedError(err));
break;
case 'ENOTFOUND':
reject(new sequelizeErrors.HostNotFoundError(err));
break;
case 'EHOSTUNREACH':
reject(new sequelizeErrors.HostNotReachableError(err));
break;
case 'EINVAL':
reject(new Error('Failed to find PostgresSQL server. Please double check your settings.'));
reject(new sequelizeErrors.InvalidConnectionError(err));
break;
default:
reject(err);
reject(new sequelizeErrors.ConnectionError(err));
break;
}
} else {
reject(new Error(err.message));
reject(new sequelizeErrors.ConnectionError(err));
}
return;
}
......@@ -79,7 +84,7 @@ ConnectionManager.prototype.connect = function(config) {
// If we didn't ever hear from the client.connect() callback the connection timeout, node-postgres does not treat this as an error since no active query was ever emitted
connection.on('end', function () {
if (!responded) {
reject(new Error('Connection timed out'));
reject(new sequelizeErrors.ConnectionTimedOutError(new Error('Connection timed out')));
}
});
}).tap(function (connection) {
......
......@@ -169,6 +169,17 @@ error.InvalidConnectionError = function (parent) {
util.inherits(error.InvalidConnectionError, error.ConnectionError);
/**
* Thrown when a connection to a database times out
* @extends ConnectionError
* @constructor
*/
error.ConnectionTimedOutError = function (parent) {
error.ConnectionTimedOutError.call(this, parent);
this.name = 'SequelizeConnectionTimedOutError';
};
util.inherits(error.ConnectionTimedOutError, 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!