return 400 (instead of 404) on invalid captures

This commit is contained in:
Sönke Hahn 2016-03-23 15:06:38 +08:00
parent b4eef7acde
commit 09c40f61e2
3 changed files with 4 additions and 4 deletions

View File

@ -127,7 +127,7 @@ instance (KnownSymbol capture, FromHttpApiData a, HasServer sublayout context)
route (Proxy :: Proxy sublayout)
context
(addCapture d $ case parseUrlPieceMaybe first :: Maybe a of
Nothing -> return $ Fail err404
Nothing -> return $ Fail err400
Just v -> return $ Route v
)

View File

@ -63,7 +63,7 @@ errorOrderSpec =
let badContentType = (hContentType, "text/plain")
badAccept = (hAccept, "text/plain")
badMethod = methodGet
badUrl = "home/nonexistent"
badUrl = "nonexistent"
badBody = "nonsense"
badAuth = (hAuthorization, "Basic foofoofoo")
goodContentType = (hContentType, "application/json")

View File

@ -202,8 +202,8 @@ captureSpec = do
response <- get "/2"
liftIO $ decode' (simpleBody response) `shouldBe` Just tweety
it "returns 404 if the decoding fails" $ do
get "/notAnInt" `shouldRespondWith` 404
it "returns 400 if the decoding fails" $ do
get "/notAnInt" `shouldRespondWith` 400
with (return (serve
(Proxy :: Proxy (Capture "captured" String :> Raw))