git.iko.soy/typeable/servant
on master help sign in
return 400 (instead of 404) on invalid captures
09c40f6Sönke Hahn
servant-server/src/Servant/Server/Internal.hs+1−1
@@ -127,7 +127,7 @@ instance (KnownSymbol capture, FromHttpApiData a, HasServer sublayout context)
127 route (Proxy :: Proxy sublayout)
127 route (Proxy :: Proxy sublayout)
128 context
128 context
129 (addCapture d $ case parseUrlPieceMaybe first :: Maybe a of
129 (addCapture d $ case parseUrlPieceMaybe first :: Maybe a of
130− Nothing -> return $ Fail err404
130+ Nothing -> return $ Fail err400
131 Just v -> return $ Route v
131 Just v -> return $ Route v
132 )
132 )
133
133
servant-server/test/Servant/Server/ErrorSpec.hs+1−1
@@ -63,7 +63,7 @@ errorOrderSpec =
63 let badContentType = (hContentType, "text/plain")
63 let badContentType = (hContentType, "text/plain")
64 badAccept = (hAccept, "text/plain")
64 badAccept = (hAccept, "text/plain")
65 badMethod = methodGet
65 badMethod = methodGet
66− badUrl = "home/nonexistent"
66+ badUrl = "nonexistent"
67 badBody = "nonsense"
67 badBody = "nonsense"
68 badAuth = (hAuthorization, "Basic foofoofoo")
68 badAuth = (hAuthorization, "Basic foofoofoo")
69 goodContentType = (hContentType, "application/json")
69 goodContentType = (hContentType, "application/json")
servant-server/test/Servant/ServerSpec.hs+2−2
@@ -202,8 +202,8 @@ captureSpec = do
202 response <- get "/2"
202 response <- get "/2"
203 liftIO $ decode' (simpleBody response) `shouldBe` Just tweety
203 liftIO $ decode' (simpleBody response) `shouldBe` Just tweety
204
204
205− it "returns 404 if the decoding fails" $ do
205+ it "returns 400 if the decoding fails" $ do
206− get "/notAnInt" `shouldRespondWith` 404
206+ get "/notAnInt" `shouldRespondWith` 400
207
207
208 with (return (serve
208 with (return (serve
209 (Proxy :: Proxy (Capture "captured" String :> Raw))
209 (Proxy :: Proxy (Capture "captured" String :> Raw))