mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-05-12 17:58:40 +08:00
android: fixed once and on error handling
This commit is contained in:
@@ -213,17 +213,41 @@ export default class Database extends Base {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param err
|
||||
* Converts an native error object to a 'firebase like' error.
|
||||
* @param error
|
||||
* @returns {Error}
|
||||
* @private
|
||||
*/
|
||||
_handleDatabaseError(err: Object) {
|
||||
const body = err.body || {};
|
||||
const { path, modifiersString, eventName, msg } = body;
|
||||
const handle = this._handle(path, modifiersString);
|
||||
_toFirebaseError(error) {
|
||||
const { path, message, modifiers, code, details } = error;
|
||||
let firebaseMessage = `FirebaseError: ${message}`;
|
||||
|
||||
this.log.debug('_handleDatabaseError ->', handle, eventName, err);
|
||||
if (path) {
|
||||
firebaseMessage = `${firebaseMessage}\r\nPath: /${path}\r\n`;
|
||||
}
|
||||
|
||||
if (this.errorSubscriptions[handle]) this.errorSubscriptions[handle].forEach((cb) => cb(new Error(msg)));
|
||||
const firebaseError = new Error(firebaseMessage);
|
||||
|
||||
firebaseError.code = code;
|
||||
firebaseError.path = path;
|
||||
firebaseError.details = details;
|
||||
firebaseError.modifiers = modifiers;
|
||||
|
||||
return firebaseError;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param error
|
||||
* @private
|
||||
*/
|
||||
_handleDatabaseError(error: Object = {}) {
|
||||
const { path, modifiers } = error;
|
||||
const handle = this._handle(path, modifiers);
|
||||
const firebaseError = this._toFirebaseError(error);
|
||||
|
||||
this.log.debug('_handleDatabaseError ->', handle, 'database_error', error);
|
||||
|
||||
if (this.errorSubscriptions[handle]) this.errorSubscriptions[handle].forEach(listener => listener(firebaseError));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user