diff --git a/lib/modules/database/reference.js b/lib/modules/database/reference.js index 5f1bc323..9c908585 100644 --- a/lib/modules/database/reference.js +++ b/lib/modules/database/reference.js @@ -481,30 +481,38 @@ export default class Reference extends ReferenceBase { * Access then method of promise if set * @return {*} */ - get then() { - if (this._promise && this._promise.then) { - return this._promise.then.bind(this._promise)(() => { + then(fnResolve, fnReject) { + if (isFunction(fnResolve) && this._promise && this._promise.then) { + return this._promise.then.bind(this._promise)((result) => { this._promise = null; - return this; + return fnResolve(result); + }, (possibleErr) => { + this._promise = null; + + if (isFunction(fnReject)) { + return fnReject(possibleErr); + } + + throw possibleErr; }); } - return undefined; + return throw new Error("Cannot read property 'then' of undefined."); } /** * Access catch method of promise if set * @return {*} */ - get catch() { - if (this._promise && this._promise.catch) { - return this._promise.catch.bind(this._promise)((exception) => { + catch(fnReject) { + if (isFunction(fnReject) && this._promise && this._promise.catch) { + return this._promise.catch.bind(this._promise)((possibleErr) => { this._promise = null; - return Promise.reject(exception); + return fnReject(possibleErr); }); } - return undefined; + return throw new Error("Cannot read property 'catch' of undefined."); } /**