diff --git a/src/db.js b/src/db.js index 4d9cc4a9..f9646f98 100644 --- a/src/db.js +++ b/src/db.js @@ -1,10 +1,12 @@ +const EventEmitter = require('events').EventEmitter; //node 0.10 compatibility; const pg = require('pg'); const Promise = require("bluebird"); const migrations = require('./migrations'); const url = require('url'); -class Db { +class Db extends EventEmitter { constructor(config){ + super(); this.config = config; @@ -21,6 +23,7 @@ class Db { max: poolConfig.poolSize }); + this.pool.on('error', error => this.emit('error', error)); function parseConnectionString(connectionString){ const params = url.parse(connectionString); diff --git a/src/index.js b/src/index.js index dcc3455b..1da42845 100644 --- a/src/index.js +++ b/src/index.js @@ -26,6 +26,7 @@ class PgBoss extends EventEmitter { this.config = config; const db = new Db(config); + db.on('error', error => this.emit('error', error)); // contractor makes sure we have a happy database home for work this.contractor = new Contractor(db, config);