File tree Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -110,11 +110,17 @@ instance A.FromJSON Request where
110
110
(Request <$>
111
111
x .: " method" <*>
112
112
(parseParams =<< x .:? " params" .!= emptyObject) <*>
113
- ( Just <$> x .: idKey <|> return Nothing )) -- (.:?) parses Null value as Nothing
113
+ parseId)
114
114
where parseParams (A. Object obj) = return $ Left obj
115
115
parseParams (A. Array ar) = return $ Right ar
116
116
parseParams _ = empty
117
117
checkVersion ver = when (ver /= jsonRpcVersion) (fail $ " Wrong JSON RPC version: " ++ unpack ver)
118
+ -- (.:?) parses Null value as Nothing so parseId needs
119
+ -- to use both (.:?) and (.:) to handle all cases
120
+ parseId = x .:? idKey >>= \ optional ->
121
+ case optional of
122
+ Nothing -> Just <$> (x .: idKey) <|> return Nothing
123
+ _ -> return optional
118
124
parseJSON _ = empty
119
125
120
126
data Response = Response Id (Either RpcError A. Value )
You can’t perform that action at this time.
0 commit comments