From faa6825537a8fc376d186923afb4f295af9b70e9 Mon Sep 17 00:00:00 2001 From: "Andres G. Aragoneses" Date: Wed, 27 Jan 2021 18:49:31 +0800 Subject: [PATCH] Backend/Ether: refactor some error handling to avoid repetition And at the same time hopefully we workaround a fantomas bug which might be tricky to fix: https://github.com/fsprojects/fantomas/issues/1390 --- src/GWallet.Backend/Ether/EtherServer.fs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/GWallet.Backend/Ether/EtherServer.fs b/src/GWallet.Backend/Ether/EtherServer.fs index fe2f1fd02..136ff0154 100644 --- a/src/GWallet.Backend/Ether/EtherServer.fs +++ b/src/GWallet.Backend/Ether/EtherServer.fs @@ -174,16 +174,21 @@ module Server = | _ -> () + let private err32kPossibleMessages = + [ + "pruning=archive" + "header not found" + "error: no suitable peers available" + "missing trie node" + ] + let MaybeRethrowRpcResponseException (ex: Exception): unit = let maybeRpcResponseEx = FSharpUtil.FindException ex match maybeRpcResponseEx with | Some rpcResponseEx -> if rpcResponseEx.RpcError <> null then if rpcResponseEx.RpcError.Code = int RpcErrorCode.StatePruningNodeOrMissingTrieNodeOrHeaderNotFound then - if (not (rpcResponseEx.RpcError.Message.Contains "pruning=archive")) && - (not (rpcResponseEx.RpcError.Message.Contains "header not found")) && - (not (rpcResponseEx.RpcError.Message.Contains "error: no suitable peers available")) && - (not (rpcResponseEx.RpcError.Message.Contains "missing trie node")) then + if not (err32kPossibleMessages.Any (fun msg -> rpcResponseEx.RpcError.Message.Contains msg)) then raise <| Exception( SPrintF2 "Expecting 'pruning=archive' or 'missing trie node' or 'error: no suitable peers available' or 'header not found' in message of a %d code, but got '%s'" (int RpcErrorCode.StatePruningNodeOrMissingTrieNodeOrHeaderNotFound)