From: Eugene Crosser Date: Tue, 25 Mar 2014 06:26:36 +0000 (+0400) Subject: wip JsonRpc response parsing X-Git-Tag: 0.9.0.0~124 X-Git-Url: http://www.average.org/gitweb/?p=pdns-pipe-nmc.git;a=commitdiff_plain;h=a0ac4a88c7f48dac8e4a79d1b7ac17a19057d662 wip JsonRpc response parsing --- 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