@@ -20,7 +20,7 @@ module Network.JsonRpc.Types ( RpcResult
20
20
, Request (.. )
21
21
, Response (.. )
22
22
, Id (.. )
23
- , RpcError
23
+ , RpcError ( .. )
24
24
, rpcError
25
25
, rpcErrorWithData ) where
26
26
@@ -56,7 +56,7 @@ infixr :+:
56
56
-- monad ('m'), and return type ('r'). 'p' has one 'Parameter' for
57
57
-- every argument of 'f' and is terminated by @()@. The return type
58
58
-- of 'f' is @RpcResult m r@. This class is treated as closed.
59
- class (Monad m , Functor m , A. ToJSON r ) => MethodParams f p m r | f -> p m r where
59
+ class (Monad m , Functor m , A. ToJSON r ) => MethodParams f p m r | f -> p m r , p m r -> f where
60
60
apply :: f -> p -> Args -> RpcResult m r
61
61
62
62
instance (Monad m , Functor m , A. ToJSON r ) => MethodParams (RpcResult m r ) () m r where
@@ -153,9 +153,11 @@ instance A.ToJSON Id where
153
153
toJSON (IdNumber x) = x
154
154
toJSON IdNull = A. Null
155
155
156
- -- | Error to be returned to the client.
157
- data RpcError = RpcError Int Text (Maybe A. Value )
158
- deriving Show
156
+ -- | JSON-RPC error.
157
+ data RpcError = RpcError { errCode :: Int
158
+ , errMsg :: Text
159
+ , errData :: Maybe A. Value }
160
+ deriving (Show , Eq )
159
161
160
162
instance Error RpcError where
161
163
noMsg = strMsg " unknown error"
@@ -167,6 +169,13 @@ instance A.ToJSON RpcError where
167
169
, Just $ " message" .= msg
168
170
, (" data" .= ) <$> data' ]
169
171
172
+ instance A. FromJSON RpcError where
173
+ parseJSON = A. withObject " JSON-RPC error object" $
174
+ \ v -> RpcError <$>
175
+ v .: " code" <*>
176
+ v .: " message" <*>
177
+ v .:? " data"
178
+
170
179
-- | Creates an 'RpcError' with the given error code and message.
171
180
-- According to the specification, server error codes should be
172
181
-- in the range -32099 to -32000, and application defined errors
0 commit comments