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

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 @@ ...@@ -2,7 +2,8 @@
var AbstractConnectionManager = require('../abstract/connection-manager') var AbstractConnectionManager = require('../abstract/connection-manager')
, ConnectionManager , ConnectionManager
, Utils = require('../../utils') , Utils = require('../../utils')
, Promise = require('../../promise'); , Promise = require('../../promise')
, sequelizeErrors = require('../../errors');
ConnectionManager = function(dialect, sequelize) { ConnectionManager = function(dialect, sequelize) {
AbstractConnectionManager.call(this, dialect, sequelize); AbstractConnectionManager.call(this, dialect, sequelize);
...@@ -56,19 +57,23 @@ ConnectionManager.prototype.connect = function(config) { ...@@ -56,19 +57,23 @@ ConnectionManager.prototype.connect = function(config) {
if (err.code) { if (err.code) {
switch (err.code) { switch (err.code) {
case 'ECONNREFUSED': case 'ECONNREFUSED':
reject(new Error('Failed to authenticate for PostgresSQL. Please double check your settings.')); reject(new sequelizeErrors.ConnectionRefusedError(err));
break; break;
case 'ENOTFOUND': case 'ENOTFOUND':
reject(new sequelizeErrors.HostNotFoundError(err));
break;
case 'EHOSTUNREACH': case 'EHOSTUNREACH':
reject(new sequelizeErrors.HostNotReachableError(err));
break;
case 'EINVAL': case 'EINVAL':
reject(new Error('Failed to find PostgresSQL server. Please double check your settings.')); reject(new sequelizeErrors.InvalidConnectionError(err));
break; break;
default: default:
reject(err); reject(new sequelizeErrors.ConnectionError(err));
break; break;
} }
} else { } else {
reject(new Error(err.message)); reject(new sequelizeErrors.ConnectionError(err));
} }
return; return;
} }
...@@ -79,7 +84,7 @@ ConnectionManager.prototype.connect = function(config) { ...@@ -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 // 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 () { connection.on('end', function () {
if (!responded) { if (!responded) {
reject(new Error('Connection timed out')); reject(new sequelizeErrors.ConnectionTimedOutError(new Error('Connection timed out')));
} }
}); });
}).tap(function (connection) { }).tap(function (connection) {
......
...@@ -169,6 +169,17 @@ error.InvalidConnectionError = function (parent) { ...@@ -169,6 +169,17 @@ error.InvalidConnectionError = function (parent) {
util.inherits(error.InvalidConnectionError, error.ConnectionError); 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 * Thrown when a database query times out because of a deadlock
* @extends DatabaseError * @extends DatabaseError
* @constructor * @constructor
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!