Skip to content

Commit

Permalink
return 400 (instead of 404) on invalid captures
Browse files Browse the repository at this point in the history
  • Loading branch information
soenkehahn committed Mar 26, 2016
1 parent b4eef7a commit 09c40f6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion servant-server/src/Servant/Server/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
2 changes: 1 addition & 1 deletion servant-server/test/Servant/Server/ErrorSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions servant-server/test/Servant/ServerSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 09c40f6

Please sign in to comment.