Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_handleErrorEvent(event) {
// console.log('SyncTree.ERROR >>>', event);
const { eventRegistrationKey, registrationCancellationKey } = event.registration;
const registration = this.getRegistration(registrationCancellationKey);
if (registration) {
// build a new js error - we additionally attach
// the ref as a property for easier debugging
const error = NativeError.fromEvent(event.error, 'database');
// forward on to users .on(successCallback, cancellationCallback <-- listener
SharedEventEmitter.emit(registrationCancellationKey, error);
// remove the paired event registration - if we received a cancellation
// event then it's guaranteed that they'll be no further value events
this.removeRegistration(eventRegistrationKey);
}
}
_handleError(event) {
const transaction = this._getTransaction(event.id);
if (transaction && !transaction.completed) {
transaction.completed = true;
try {
// error, committed, snapshot
const error = NativeError.fromEvent(event.body.error, 'database');
transaction.onComplete(error, false, null);
} finally {
this._removeTransaction(event.id);
}
}
}
event => {
if (event.body.error) {
handleError(NativeError.fromEvent(event.body.error, 'firestore'));
} else {
const documentSnapshot = new FirestoreDocumentSnapshot(
this._firestore,
event.body.snapshot,
);
handleSuccess(documentSnapshot);
}
},
);
_handleError(event) {
const { listenerId: id, body } = event;
const { error } = body;
if (!this._pending[id]) {
return;
}
const { meta } = this._pending[id];
if (meta && error) {
const errorAndStack = NativeError.fromEvent(error, 'firestore', meta.stack);
meta.reject(errorAndStack);
}
}
_handleAdEvent(event) {
const { type, error, data } = event.body;
if (type === AdEventType.LOADED || type === RewardedAdEventType.LOADED) {
this._loaded = true;
}
if (this._onAdEventHandler) {
let nativeError;
if (error) {
nativeError = NativeError.fromEvent(error, 'admob');
}
this._onAdEventHandler(type, nativeError, data);
}
}
event => {
if (event.body.error) {
handleError(NativeError.fromEvent(event.body.error, 'firestore'));
} else {
const querySnapshot = new FirestoreQuerySnapshot(
this._firestore,
this,
event.body.snapshot,
);
handleSuccess(querySnapshot);
}
},
);