From ddd7203a00610174c766bb658a73198dc80d9d13 Mon Sep 17 00:00:00 2001 From: Mikkel Schmidt Date: Thu, 12 Sep 2013 18:53:21 +0200 Subject: [PATCH] Added error callback to list() on DbQueryCollection as sql might fail --- lib/persistence.store.sql.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/persistence.store.sql.js b/lib/persistence.store.sql.js index 3db93c3..a8efe7d 100644 --- a/lib/persistence.store.sql.js +++ b/lib/persistence.store.sql.js @@ -579,19 +579,21 @@ function config(persistence, dialect) { * @param callback function to be called taking an array with * result objects as argument */ - persistence.DbQueryCollection.prototype.list = function (tx, callback) { + persistence.DbQueryCollection.prototype.list = function (tx, callback, errorCallback) { var args = argspec.getArgs(arguments, [ { name: 'tx', optional: true, check: persistence.isTransaction, defaultValue: null }, - { name: 'callback', optional: false, check: argspec.isCallback() } + { name: 'callback', optional: false, check: argspec.isCallback() }, + { name: 'errorCallback', optional: true, check: argspec.isCallback(), defaultValue: null } ]); tx = args.tx; callback = args.callback; + errorCallback = args.errorCallback; var that = this; var session = this._session; if(!tx) { // no transaction supplied session.transaction(function(tx) { - that.list(tx, callback); + that.list(tx, callback, errorCallback); }); return; } @@ -708,6 +710,13 @@ function config(persistence, dialect) { } callback(results); that.triggerEvent('list', that, results); + }, function (tx, error) { + if (persistence.debug) { + console.log(tx, error); + } + if (typeof errorCallback == 'function') { + errorCallback(tx, error); + } }); }); };