Issue 404 for nonexistent tables

Fixes #44
This commit is contained in:
Joe Nelson
2014-10-14 18:58:55 -07:00
parent 36b62de998
commit 93c573ab4f
2 changed files with 9 additions and 5 deletions
+5 -5
View File
@@ -18,7 +18,7 @@ import Control.Exception (finally, throw, catchJust, catch, SomeException,
import Network.HTTP.Types.Header (RequestHeaders, hContentType, hAuthorization,
hLocation)
import Network.HTTP.Types.Status (status400, status401, status301)
import Network.HTTP.Types.Status (status400, status401, status404, status301)
import Network.Wai (Application, requestHeaders, responseLBS, rawPathInfo,
rawQueryString, isSecure)
import Network.URI (URI(..), parseURI)
@@ -72,10 +72,10 @@ instance ToJSON SqlError where
clientErrors :: Application -> Application
clientErrors app req respond =
catchJust isPgException (app req respond) (
respond . responseLBS status400 [(hContentType, "application/json")]
. encode
)
catchJust isPgException (app req respond) $ \err ->
respond $ if seState err == "42P01"
then responseLBS status404 [] ""
else responseLBS status400 [(hContentType, "application/json")] (encode err)
where
isPgException :: SqlError -> Maybe SqlError
+4
View File
@@ -9,6 +9,10 @@ import SpecHelper
spec :: Spec
spec = around appWithFixture $ do
describe "Querying a nonexistent table" $
it "causes a 404" $
get "/faketable" `shouldRespondWith` 404
describe "Filtering response" $
context "column equality" $