js: change db error to match firebase web sdk error
This commit is contained in:
parent
51c63b2f3e
commit
2d1015d205
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"ignore_dirs": [
|
||||
".git",
|
||||
"node_modules",
|
||||
"android/build",
|
||||
"android/.idea",
|
||||
"android/.gradle",
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue