From e4cf1ce20708981efac7c00876111b7ae22d0007 Mon Sep 17 00:00:00 2001 From: Joe Nelson Date: Wed, 6 Jul 2016 21:48:32 -0700 Subject: [PATCH] Translate raise_exception to http 400 Fixes #661 --- CHANGELOG.md | 3 +++ src/PostgREST/Error.hs | 1 + test/Feature/QuerySpec.hs | 4 +++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ea6aa688..301cc04fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,9 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Fixed - Do not apply limit to parent items - @ruslantalpa +### Changed +- Use HTTP 400 for raise\_exception - @begriffs + ## [0.3.2.0] - 2016-06-10 ### Added diff --git a/src/PostgREST/Error.hs b/src/PostgREST/Error.hs index 5b04cdfa2..92ae84fa4 100644 --- a/src/PostgREST/Error.hs +++ b/src/PostgREST/Error.hs @@ -86,6 +86,7 @@ httpStatus authed (P.SessionError (H.ResultError (H.ServerError c _ _ _))) = '5':'8':_ -> HT.status500 -- system error 'F':'0':_ -> HT.status500 -- conf file error 'H':'V':_ -> HT.status500 -- foreign data wrapper error + "P0001" -> HT.status400 -- default code for "raise" 'P':'0':_ -> HT.status500 -- PL/pgSQL Error 'X':'X':_ -> HT.status500 -- internal Error "42P01" -> HT.status404 -- undefined table diff --git a/test/Feature/QuerySpec.hs b/test/Feature/QuerySpec.hs index 75f896ceb..89b7643d9 100644 --- a/test/Feature/QuerySpec.hs +++ b/test/Feature/QuerySpec.hs @@ -512,7 +512,9 @@ spec = do -- it used to be 404 and it makes sense but in another part we decided that it's good to return -- PostgreSQL errors (and have the proxy handle them) and this saves us an aditional query on each rpc request it "responds with 400 on an unexisting proc" $ - post "/rpc/fake" [json| {} |] `shouldRespondWith` 400 + post "/rpc/fake" "{}" `shouldRespondWith` 400 + it "treats simple plpgsql raise as invalid input" $ + post "/rpc/problem" "{}" `shouldRespondWith` 400 context "unsupported verbs" $ do