diff --git a/src/GWallet.Backend/Ether/EtherExceptions.fs b/src/GWallet.Backend/Ether/EtherExceptions.fs index a08d73033..5fd364177 100644 --- a/src/GWallet.Backend/Ether/EtherExceptions.fs +++ b/src/GWallet.Backend/Ether/EtherExceptions.fs @@ -95,3 +95,8 @@ type UnhandledWebException = } new (info: SerializationInfo, context: StreamingContext) = { inherit Exception (info, context) } + +/// Exception indicating that response JSON contains null value where it should not. +/// E.g. {"jsonrpc":"2.0","id":1,"result":null} +type WeirdNullResponseException(message: string) = + inherit CommunicationUnsuccessfulException(message) diff --git a/src/GWallet.Backend/Ether/EtherServer.fs b/src/GWallet.Backend/Ether/EtherServer.fs index 3e86bbb9f..bfb5a2611 100644 --- a/src/GWallet.Backend/Ether/EtherServer.fs +++ b/src/GWallet.Backend/Ether/EtherServer.fs @@ -561,7 +561,7 @@ module Server = return! Async.AwaitTask task } if Object.ReferenceEquals(balance, null) then - failwith "Weird null response from balance job" + raise <| WeirdNullResponseException "Weird null response from balance job" return UnitConversion.Convert.FromWei(balance.Value, UnitConversion.EthUnit.Ether) } GetRandomizedFuncs currency web3Func diff --git a/src/GWallet.Backend/ServerManager.fs b/src/GWallet.Backend/ServerManager.fs index 958ff3d6e..6e423aa1a 100644 --- a/src/GWallet.Backend/ServerManager.fs +++ b/src/GWallet.Backend/ServerManager.fs @@ -128,6 +128,8 @@ module ServerManager = let web3Func (web3: Ether.SomeWeb3): Async = async { let! balance = Async.AwaitTask (web3.Eth.GetBalance.SendRequestAsync ETH_GENESISBLOCK_ADDRESS) + if isNull balance then + raise <| Ether.WeirdNullResponseException "Weird null response from balance job" return balance.Value |> decimal }