@@ -373,10 +373,10 @@ public void onMethodCall(MethodCall call, final Result result) {
373
373
final Map <String , Object > arguments = call .arguments ();
374
374
getFirestore (arguments )
375
375
.runTransaction (
376
- new Transaction .Function <Map < String , Object > >() {
376
+ new Transaction .Function <TransactionResult >() {
377
377
@ Nullable
378
378
@ Override
379
- public Map < String , Object > apply (@ NonNull Transaction transaction ) {
379
+ public TransactionResult apply (@ NonNull Transaction transaction ) {
380
380
// Store transaction.
381
381
int transactionId = (Integer ) arguments .get ("transactionId" );
382
382
transactions .append (transactionId , transaction );
@@ -424,23 +424,31 @@ public void notImplemented() {
424
424
Tasks .await (transactionTCSTask , timeout , TimeUnit .MILLISECONDS );
425
425
426
426
// Once transaction completes return the result to the Dart side.
427
- return transactionResult ;
427
+ return new TransactionResult ( transactionResult ) ;
428
428
} catch (Exception e ) {
429
429
Log .e (TAG , e .getMessage (), e );
430
- result . error ( "Error performing transaction" , e . getMessage (), null );
430
+ return new TransactionResult ( e );
431
431
}
432
- return null ;
433
432
}
434
433
})
435
434
.addOnCompleteListener (
436
- new OnCompleteListener <Map < String , Object > >() {
435
+ new OnCompleteListener <TransactionResult >() {
437
436
@ Override
438
- public void onComplete (Task <Map <String , Object >> task ) {
439
- if (task .isSuccessful ()) {
440
- result .success (task .getResult ());
441
- } else {
437
+ public void onComplete (Task <TransactionResult > task ) {
438
+ if (!task .isSuccessful ()) {
442
439
result .error (
443
440
"Error performing transaction" , task .getException ().getMessage (), null );
441
+ return ;
442
+ }
443
+
444
+ TransactionResult transactionResult = task .getResult ();
445
+ if (transactionResult .exception == null ) {
446
+ result .success (transactionResult .result );
447
+ } else {
448
+ result .error (
449
+ "Error performing transaction" ,
450
+ transactionResult .exception .getMessage (),
451
+ null );
444
452
}
445
453
}
446
454
});
@@ -820,6 +828,21 @@ public void onFailure(@NonNull Exception e) {
820
828
}
821
829
}
822
830
}
831
+
832
+ private static final class TransactionResult {
833
+ final @ Nullable Map <String , Object > result ;
834
+ final @ Nullable Exception exception ;
835
+
836
+ TransactionResult (@ NonNull Exception exception ) {
837
+ this .exception = exception ;
838
+ this .result = null ;
839
+ }
840
+
841
+ TransactionResult (@ Nullable Map <String , Object > result ) {
842
+ this .result = result ;
843
+ this .exception = null ;
844
+ }
845
+ }
823
846
}
824
847
825
848
final class FirestoreMessageCodec extends StandardMessageCodec {
0 commit comments