@@ -54,7 +54,7 @@ exports.initialize = function initializeDataSource(dataSource, callback) {
5454 *
5555 * @param {PostgreSQL } postgresql PostgreSQL node.js binding
5656 * @options {Object} settings An object for the data source settings.
57- * See [node-postgres documentation](https://github.com/brianc/ node-postgres/wiki/Client#parameters ).
57+ * See [node-postgres documentation](https://node-postgres.com/api/client ).
5858 * @property {String } url URL to the database, such as 'postgres://test:mypassword@localhost:5432/devdb'.
5959 * Other parameters can be defined as query string of the url
6060 * @property {String } hostname The host name or ip address of the PostgreSQL DB server
@@ -63,6 +63,8 @@ exports.initialize = function initializeDataSource(dataSource, callback) {
6363 * @property {String } password The password
6464 * @property {String } database The database name
6565 * @property {Boolean } ssl Whether to try SSL/TLS to connect to server
66+ * @property {Function | string } [onError] Optional hook to connect to the pg pool 'error' event,
67+ * or the string 'ignore' to record them with `debug` and otherwise ignore them.
6668 *
6769 * @constructor
6870 */
@@ -79,6 +81,16 @@ function PostgreSQL(postgresql, settings) {
7981 this . clientConfig . Promise = Promise ;
8082 this . pg = new postgresql . Pool ( this . clientConfig ) ;
8183
84+ if ( settings . onError ) {
85+ if ( settings . onError === 'ignore' ) {
86+ this . pg . on ( 'error' , function ( err ) {
87+ debug ( err ) ;
88+ } ) ;
89+ } else {
90+ this . pg . on ( 'error' , settings . onError ) ;
91+ }
92+ }
93+
8294 this . settings = settings ;
8395 debug ( 'Settings %j' , settings ) ;
8496}
0 commit comments