Skip to content

Commit

Permalink
handle Null error throwing a proper exception
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagocarvalhodev committed Jul 22, 2024
1 parent e377482 commit 493c094
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/services/arweave/arweave_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'dart:convert';

import 'package:ardrive/core/crypto/crypto.dart';
import 'package:ardrive/entities/entities.dart';
import 'package:ardrive/services/arweave/arweave_service_exception.dart';
import 'package:ardrive/services/arweave/error/gateway_error.dart';
import 'package:ardrive/services/arweave/get_segmented_transaction_from_drive_strategy.dart';
import 'package:ardrive/services/services.dart';
Expand Down Expand Up @@ -117,8 +118,18 @@ class ArweaveService {

/// Returns the pending transaction fees of the specified address that is not reflected by `getWalletBalance()`.
Future<BigInt> getPendingTxFees(String address) async {
final query = await graphQLRetry.execute(PendingTxFeesQuery(
variables: PendingTxFeesArguments(walletAddress: address)));
final query = await graphQLRetry.execute(
PendingTxFeesQuery(
variables: PendingTxFeesArguments(
walletAddress: address,
),
),
);

if (query.data == null) {
throw ArweaveServiceException(
'Error fetching pending transaction fees. The query `PendingTxFeesQuery` returned null');
}

return query.data!.transactions.edges
.map((edge) => edge.node)
Expand Down
10 changes: 10 additions & 0 deletions lib/services/arweave/arweave_service_exception.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class ArweaveServiceException implements Exception {
final String message;

ArweaveServiceException(this.message);

@override
String toString() {
return 'ArweaveServiceException: $message';
}
}

0 comments on commit 493c094

Please sign in to comment.