Skip to content

Commit

Permalink
fix: capture error from getting balance
Browse files Browse the repository at this point in the history
  • Loading branch information
markettes committed Nov 22, 2024
1 parent 315bc25 commit 11e8518
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/Rpc/NodeGuardService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -382,23 +382,31 @@ public override async Task<GetAvailableWalletsResponse> GetAvailableWallets(GetA

public override async Task<GetWalletBalanceResponse> 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));
}
}


Expand Down

0 comments on commit 11e8518

Please sign in to comment.