From a0ac4a88c7f48dac8e4a79d1b7ac17a19057d662 Mon Sep 17 00:00:00 2001 From: Eugene Crosser Date: Tue, 25 Mar 2014 10:26:36 +0400 Subject: [PATCH] wip JsonRpc response parsing --- Data/JsonRpc.hs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Data/JsonRpc.hs b/Data/JsonRpc.hs index d8a22b3..15b1d88 100644 --- a/Data/JsonRpc.hs +++ b/Data/JsonRpc.hs @@ -72,4 +72,11 @@ instance FromJSON JsonRpcResponse where "" parseJsonRpc :: (FromJSON a) => ByteString -> Either JsonRpcError a -parseJsonRpc _ = Left $ JsonRpcError (-1) "someerror" Nothing +parseJsonRpc s = case (decode s :: Maybe JsonRpcResponse) of + Just (JsonRpcResponse result error id) -> + case result of + Just v -> case (fromJSON v) of + Success a -> Right a + Error s -> Left $ JsonRpcError (-32900) "Unparseable result" Nothing + Nothing -> Left error + Nothing -> Left $ JsonRpcError (-32800) "Unparseable response" Nothing -- 2.39.2