From 90ea56534b6105780c97b77e23a165c9932f5759 Mon Sep 17 00:00:00 2001 From: Alp Mestanogullari Date: Tue, 28 Oct 2014 16:58:46 +0100 Subject: [PATCH] add a testcase to very that we reject invalid json bodies with HTTP status 400 --- src/Servant/Server.hs | 2 +- test/Servant/ServerSpec.hs | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Servant/Server.hs b/src/Servant/Server.hs index 72166f0c..fe1f42f0 100644 --- a/src/Servant/Server.hs +++ b/src/Servant/Server.hs @@ -36,7 +36,7 @@ toApplication ra request respond = do data RouteMismatch = NotFound -- ^ the usual "not found" error | WrongMethod -- ^ a more informative "you just got the HTTP method wrong" error - | InvalidBody -- ^ an even more informative "you json request body wasn't valid" error + | InvalidBody -- ^ an even more informative "your json request body wasn't valid" error deriving (Eq, Show) -- | diff --git a/test/Servant/ServerSpec.hs b/test/Servant/ServerSpec.hs index ed64864c..6a244da8 100644 --- a/test/Servant/ServerSpec.hs +++ b/test/Servant/ServerSpec.hs @@ -154,6 +154,9 @@ postSpec = do matchStatus = 201 } + it "correctly rejects invalid request bodies with status 400" $ do + post "/" "some invalid body" `shouldRespondWith` 400 + type RawApi = "foo" :> Raw rawApi :: Proxy RawApi