mirror of
https://github.com/brianc/node-postgres.git
synced 2026-01-18 15:55:05 +00:00
connection raising error from libpq error
This commit is contained in:
parent
dde73c68d7
commit
93c1135389
@ -13,6 +13,7 @@ using namespace v8;
|
||||
using namespace node;
|
||||
|
||||
static Persistent<String> connect_symbol;
|
||||
static Persistent<String> error_symbol;
|
||||
|
||||
class Connection : public EventEmitter {
|
||||
|
||||
@ -30,6 +31,7 @@ public:
|
||||
t->SetClassName(String::NewSymbol("Connection"));
|
||||
|
||||
connect_symbol = NODE_PSYMBOL("connect");
|
||||
error_symbol = NODE_PSYMBOL("error");
|
||||
|
||||
NODE_SET_PROTOTYPE_METHOD(t, "connect", Connect);
|
||||
NODE_SET_PROTOTYPE_METHOD(t, "_sendQuery", SendQuery);
|
||||
@ -275,6 +277,8 @@ private:
|
||||
StopRead();
|
||||
StopWrite();
|
||||
LOG("Polled: PGRES_POLLING_FAILED");
|
||||
EmitLastError();
|
||||
EmitError("Something happened...polling error");
|
||||
break;
|
||||
case PGRES_POLLING_OK:
|
||||
LOG("Polled: PGRES_POLLING_OK");
|
||||
@ -287,6 +291,17 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
void EmitError(const char *message)
|
||||
{
|
||||
Local<Value> exception = Exception::Error(String::New(message));
|
||||
Emit(error_symbol, 1, &exception);
|
||||
}
|
||||
|
||||
void EmitLastError()
|
||||
{
|
||||
EmitError(PQerrorMessage(connection_));
|
||||
}
|
||||
|
||||
void StopWrite()
|
||||
{
|
||||
TRACE("Stoping write watcher");
|
||||
|
||||
@ -15,7 +15,9 @@ test('calling connect without params raises error', function() {
|
||||
test('connecting with wrong parameters', function() {
|
||||
var con = new Connection();
|
||||
con.connect("user=asldfkj hostaddr=127.0.0.1 port=5432 dbname=asldkfj");
|
||||
assert.emits(con, 'error')
|
||||
assert.emits(con, 'error', function(error) {
|
||||
console.log(error);
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user