I am updating my document with this code.
Future<void> save() async {
print('league save');
final DocumentReference ref =
Firestore.instance.collection('leagues').document(_documentName);
Firestore.instance.runTransaction((Transaction tx) async {
DocumentSnapshot postSnapshot = await tx.get(ref);
if (postSnapshot.exists) {
await tx.update(ref, _getDocument());
print('league save complete');
}
});
}
I believe that this may be failing sometimes but I am not sure. I am got getting an error.
The reason I suspect it is failing sometimes is because my listener (elsewhere in the app) isn't always getting fired when the document changes.
How do I log or capture an error in the transaction?
答案 0 :(得分:0)
runTransaction只是一个普通的异步操作,您可以通过then和catchError进行后续操作:
Firestore.instance.runTransaction((Transaction tx) async {
// do whatever
}).then((val) {
// do something upon success
}).catchError((e) {
// do something upon error
});
,然后您可以跳过.then()