]> www.average.org Git - pdns-pipe-nmc.git/commitdiff
wip JsonRpc response parsing
authorEugene Crosser <crosser@average.org>
Tue, 25 Mar 2014 06:26:36 +0000 (10:26 +0400)
committerEugene Crosser <crosser@average.org>
Tue, 25 Mar 2014 06:26:36 +0000 (10:26 +0400)
Data/JsonRpc.hs

index d8a22b3075fa4728a1a045b1f22ba9dbf3381b2b..15b1d88e99d9e447ccb650b061707458350bfc0b 100644 (file)
@@ -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