diff --git a/src/GWallet.Backend/Ether/EtherExceptions.fs b/src/GWallet.Backend/Ether/EtherExceptions.fs index a08d73033..11c6c3fc1 100644 --- a/src/GWallet.Backend/Ether/EtherExceptions.fs +++ b/src/GWallet.Backend/Ether/EtherExceptions.fs @@ -95,3 +95,10 @@ 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 AbnormalNullValueInJsonResponseException(message: string) = + inherit CommunicationUnsuccessfulException(message) + + static member BalanceJobErrorMessage = "Abnormal null response from balance job" diff --git a/src/GWallet.Backend/Ether/EtherServer.fs b/src/GWallet.Backend/Ether/EtherServer.fs index 827a144f1..b6ea6e1f6 100644 --- a/src/GWallet.Backend/Ether/EtherServer.fs +++ b/src/GWallet.Backend/Ether/EtherServer.fs @@ -543,7 +543,9 @@ module Server = return! Async.AwaitTask task } if Object.ReferenceEquals(balance, null) then - failwith "Weird null response from balance job" + raise <| + AbnormalNullValueInJsonResponseException + AbnormalNullValueInJsonResponseException.BalanceJobErrorMessage 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 dbe42a612..90f481ca8 100644 --- a/src/GWallet.Backend/ServerManager.fs +++ b/src/GWallet.Backend/ServerManager.fs @@ -128,6 +128,10 @@ 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.AbnormalNullValueInJsonResponseException + Ether.AbnormalNullValueInJsonResponseException.BalanceJobErrorMessage return balance.Value |> decimal }