From 11e8518f9e6904ab3db0b190a41b78e19cde6382 Mon Sep 17 00:00:00 2001 From: Marcos Date: Fri, 22 Nov 2024 08:58:52 +0100 Subject: [PATCH] fix: capture error from getting balance --- src/Rpc/NodeGuardService.cs | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/Rpc/NodeGuardService.cs b/src/Rpc/NodeGuardService.cs index ae209394..7b2de096 100644 --- a/src/Rpc/NodeGuardService.cs +++ b/src/Rpc/NodeGuardService.cs @@ -382,23 +382,31 @@ public override async Task GetAvailableWallets(GetA public override async Task GetWalletBalance(GetWalletBalanceRequest request, ServerCallContext context) { - var wallet = await _walletRepository.GetById(request.WalletId); - if (wallet == null) + try { - throw new RpcException(new Status(StatusCode.NotFound, "Wallet not found")); - } + var wallet = await _walletRepository.GetById(request.WalletId); + if (wallet == null) + { + throw new RpcException(new Status(StatusCode.NotFound, "Wallet not found")); + } - var balance = await _lightningService.GetWalletBalance(wallet); - if (balance == null) - { - throw new RpcException(new Status(StatusCode.Internal, "Error getting wallet balance")); + var balance = await _lightningService.GetWalletBalance(wallet); + if (balance == null) + { + throw new RpcException(new Status(StatusCode.Internal, "Error getting wallet balance")); + } + + return new GetWalletBalanceResponse + { + ConfirmedBalance = ((Money)balance.Confirmed).Satoshi, + UnconfirmedBalance = ((Money)balance.Unconfirmed).Satoshi + }; } - - return new GetWalletBalanceResponse + catch (Exception e) { - ConfirmedBalance = ((Money)balance.Confirmed).Satoshi, - UnconfirmedBalance = ((Money)balance.Unconfirmed).Satoshi - }; + _logger?.LogError(e, "Error getting wallet balance through gRPC"); + throw new RpcException(new Status(StatusCode.Internal, e.Message)); + } }