Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Network/JsonRpc/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Network.JsonRpc.Types ( RpcResult
, rpcErrorWithData) where

import Data.Maybe (catMaybes)
import Data.Text (Text)
import Data.Text (Text, append)
#if ! MIN_VERSION_aeson(2,0,0)
import Data.Text (unpack)
#endif
Expand Down Expand Up @@ -86,14 +86,14 @@ parseArg :: A.FromJSON r => Text -> A.Value -> Either RpcError r
parseArg name val = case A.fromJSON val of
A.Error msg -> throwError $ argTypeError msg
A.Success x -> return x
where argTypeError = rpcErrorWithData (-32602) $ "Wrong type for argument: " <> name
where argTypeError = rpcErrorWithData (-32602) $ "Wrong type for argument: " `append` name

paramDefault :: Parameter a -> Either RpcError a
paramDefault (Optional _ d) = Right d
paramDefault (Required name) = Left $ missingArgError name

missingArgError :: Text -> RpcError
missingArgError name = rpcError (-32602) $ "Cannot find required argument: " <> name
missingArgError name = rpcError (-32602) $ "Cannot find required argument: " `append` name

paramName :: Parameter a -> Text
paramName (Optional n _) = n
Expand Down
10 changes: 7 additions & 3 deletions tests/TestSuite.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import qualified Data.HashMap.Strict as H
import qualified Data.ByteString.Lazy.Char8 as LB
import Control.Monad.Trans (liftIO)
import Control.Monad.State (State, runState, lift, modify)
import Control.Monad.Identity (Identity(..), runIdentity)
import Control.Monad.Identity (Identity, runIdentity)
import Test.HUnit hiding (State, Test)
import Test.Framework (defaultMain, Test)
import Test.Framework.Providers.HUnit (testCase)
Expand Down Expand Up @@ -189,8 +189,12 @@ getTimeMethod = S.toMethod "get_time_seconds" getTestTime ()
getTestTime = liftIO $ return 100

removeErrMsg :: A.Value -> A.Value
removeErrMsg (A.Object rsp) = A.Object $ runIdentity $ H.alterF (Identity . fmap removeMsg) "error" rsp
where removeMsg (A.Object err) = A.Object $ H.insert "message" "" $ H.delete "data" err
removeErrMsg (A.Object rsp) = A.Object $
case H.lookup errorKey rsp of
Nothing -> rsp
Just v -> H.insert errorKey (removeMsg v) rsp
where errorKey = "error"
removeMsg (A.Object err) = A.Object $ H.insert "message" "" $ H.delete "data" err
removeMsg v = v
removeErrMsg (A.Array rsps) = A.Array $ removeErrMsg `V.map` rsps
removeErrMsg v = v
Loading