From 2d1015d2058ce7eabfa343777f58a54df20d309b Mon Sep 17 00:00:00 2001 From: Salakar Date: Wed, 8 Mar 2017 13:21:21 +0000 Subject: [PATCH] js: change db error to match firebase web sdk error --- .watchmanconfig | 1 + lib/modules/database/index.js | 5 +++-- lib/modules/database/reference.js | 21 +++++++++++++++++---- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/.watchmanconfig b/.watchmanconfig index 7ec8e5d4..ad4582d1 100644 --- a/.watchmanconfig +++ b/.watchmanconfig @@ -1,6 +1,7 @@ { "ignore_dirs": [ ".git", + "node_modules", "android/build", "android/.idea", "android/.gradle", diff --git a/lib/modules/database/index.js b/lib/modules/database/index.js index b1ad7e56..9787ec47 100644 --- a/lib/modules/database/index.js +++ b/lib/modules/database/index.js @@ -84,6 +84,7 @@ export default class Database extends Base { if (!this.subscriptions[handle]) this.subscriptions[handle] = {}; if (!this.subscriptions[handle][eventName]) this.subscriptions[handle][eventName] = []; this.subscriptions[handle][eventName].push(cb); + if (errorCb) { if (!this.errorSubscriptions[handle]) this.errorSubscriptions[handle] = []; this.errorSubscriptions[handle].push(errorCb); @@ -220,10 +221,10 @@ export default class Database extends Base { */ _toFirebaseError(error) { const { path, message, modifiers, code, details } = error; - let firebaseMessage = `FirebaseError: ${message}`; + let firebaseMessage = `FirebaseError: ${message.toLowerCase().replace(/\s/g, '_')}`; if (path) { - firebaseMessage = `${firebaseMessage}\r\nPath: /${path}\r\n`; + firebaseMessage = `${firebaseMessage} at /${path}\r\n`; } const firebaseError = new Error(firebaseMessage); diff --git a/lib/modules/database/reference.js b/lib/modules/database/reference.js index b6d9fb5b..34df82eb 100644 --- a/lib/modules/database/reference.js +++ b/lib/modules/database/reference.js @@ -77,12 +77,12 @@ export default class Reference extends ReferenceBase { */ push(value: any, onComplete: Function) { if (value === null || value === undefined) { - const _path = this.path + '/' + generatePushID(this.db.serverTimeOffset); - return new Reference(this.db, _path); + return new Reference(this.db, `${this.path}/${generatePushID(this.db.serverTimeOffset)}`); } const path = this._dbPath(); const _value = this._serializeAnyType(value); + return promisify('push', FirebaseDatabase)(path, _value) .then(({ ref }) => { const newRef = new Reference(this.db, ref); @@ -102,7 +102,7 @@ export default class Reference extends ReferenceBase { * @param context TODO * @returns {*} */ - on(eventType: string, successCallback: () => any, failureCallback: () => any, context) { + on(eventType: string, successCallback: () => any, failureCallback: () => any) { if (!isFunction(successCallback)) throw new Error('The specified callback must be a function'); if (failureCallback && !isFunction(failureCallback)) throw new Error('The specified error callback must be a function'); const path = this._dbPath(); @@ -280,14 +280,27 @@ export default class Reference extends ReferenceBase { return newRef; } + /** + * + * @returns {Disconnect} + */ onDisconnect() { return new Disconnect(this.path); } + /** + * Get a specified child + * @param path + * @returns {Reference} + */ child(path: string) { - return new Reference(this.db, this.path + '/' + path); + return new Reference(this.db, `${this.path}/${path}`); } + /** + * Return the ref as a path string + * @returns {string} + */ toString(): string { return this._dbPath(); }