3
3
FlexibleInstances,
4
4
UndecidableInstances,
5
5
TypeOperators,
6
- PatternGuards,
7
6
OverloadedStrings #-}
8
7
9
8
module Network.JsonRpc.Types ( RpcResult
@@ -55,9 +54,9 @@ class (Monad m, Functor m, A.ToJSON r) => MethodParams f p m r | f -> p m r wher
55
54
apply :: f -> p -> Args -> RpcResult m r
56
55
57
56
instance (Monad m , Functor m , A. ToJSON r ) => MethodParams (RpcResult m r ) () m r where
58
- apply r _ args | Left _ <- args = r
59
- | Right ar <- args, V. null ar = r
60
- | otherwise = throwError $ rpcError ( - 32602 ) " Too many unnamed arguments "
57
+ apply _ _ ( Right ar) | not $ V. null ar =
58
+ throwError $ rpcError ( - 32602 ) " Too many unnamed arguments "
59
+ apply res _ _ = res
61
60
62
61
instance (A. FromJSON a , MethodParams f p m r ) => MethodParams (a -> f ) (a :+: p ) m r where
63
62
apply f (param :+: ps) args = arg >>= \ a -> apply (f a) ps nextArgs
@@ -81,15 +80,16 @@ tailOrEmpty vec = if V.null vec then V.empty else V.tail vec
81
80
82
81
parseArg :: (Monad m , A. FromJSON r ) => Text -> A. Value -> RpcResult m r
83
82
parseArg name val = case A. fromJSON val of
84
- A. Error msg -> throwError $ rpcErrorWithData ( - 32602 ) ( " Wrong type for argument: " `append` name) msg
83
+ A. Error msg -> throwError $ argTypeError msg
85
84
A. Success x -> return x
85
+ where argTypeError = rpcErrorWithData (- 32602 ) $ " Wrong type for argument: " `append` name
86
86
87
87
paramDefault :: Monad m => Parameter a -> RpcResult m a
88
88
paramDefault (Optional _ d) = return d
89
89
paramDefault (Required name) = throwError $ missingArgError name
90
90
91
91
missingArgError :: Text -> RpcError
92
- missingArgError name = rpcError (- 32602 ) ( " Cannot find required argument: " `append` name)
92
+ missingArgError name = rpcError (- 32602 ) $ " Cannot find required argument: " `append` name
93
93
94
94
paramName :: Parameter a -> Text
95
95
paramName (Optional n _) = n
@@ -114,7 +114,8 @@ instance A.FromJSON Request where
114
114
where parseParams (A. Object obj) = return $ Left obj
115
115
parseParams (A. Array ar) = return $ Right ar
116
116
parseParams _ = empty
117
- checkVersion ver = when (ver /= jsonRpcVersion) (fail $ " Wrong JSON RPC version: " ++ unpack ver)
117
+ checkVersion ver = when (ver /= jsonRpcVersion) $
118
+ fail $ " Wrong JSON RPC version: " ++ unpack ver
118
119
-- (.:?) parses Null value as Nothing so parseId needs
119
120
-- to use both (.:?) and (.:) to handle all cases
120
121
parseId = x .:? idKey >>= \ optional ->
0 commit comments