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 3e86bbb9f..acf2b915c 100644 --- a/src/GWallet.Backend/Ether/EtherServer.fs +++ b/src/GWallet.Backend/Ether/EtherServer.fs @@ -561,7 +561,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 958ff3d6e..8dd56ef9e 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 }