diff --git a/lib/client.js b/lib/client.js index 378134a9d..0e0f3717c 100644 --- a/lib/client.js +++ b/lib/client.js @@ -128,12 +128,18 @@ p.submit = function(connection) { var handleDatarow = function(msg) { self.onDataRow(msg); }; + var handleError = function(msg) { + self.emit('error', msg); + connection.sync(); + }; connection.on('rowDescription', handleRowDescription); connection.on('dataRow', handleDatarow); + connection.on('error', handleError); connection.once('readyForQuery', function() { //remove all listeners connection.removeListener('rowDescription', handleRowDescription); connection.removeListener('dataRow', handleDatarow); + connection.removeListener('error', handleError); self.emit('end'); }); }; diff --git a/test/integration/client/error-handling-tests.js b/test/integration/client/error-handling-tests.js index b9e93b8b0..43ca150be 100644 --- a/test/integration/client/error-handling-tests.js +++ b/test/integration/client/error-handling-tests.js @@ -2,8 +2,8 @@ var helper = require(__dirname + '/test-helper'); test('error handling', function(){ var client = helper.client(); - client.query("select omfg from yodas_soda where pixistix = 'zoiks!!!'"); - assert.emits(client, 'error', function(error) { + var query = client.query("select omfg from yodas_soda where pixistix = 'zoiks!!!'"); + assert.emits(query, 'error', function(error) { assert.equal(error.severity, "ERROR"); client.end(); });