Merge pull request #470 from sscarduzio/patch-1
The correct HTTP status code for integrity constraint violation is 509, fixes #469
This commit is contained in:
@@ -54,6 +54,8 @@ httpStatus (H.TxError (P.ErroneousResult codeBS _ _ _)) =
|
|||||||
'0':'9':_ -> HT.status500 -- triggered action exception
|
'0':'9':_ -> HT.status500 -- triggered action exception
|
||||||
'0':'L':_ -> HT.status403 -- invalid grantor
|
'0':'L':_ -> HT.status403 -- invalid grantor
|
||||||
'0':'P':_ -> HT.status403 -- invalid role specification
|
'0':'P':_ -> HT.status403 -- invalid role specification
|
||||||
|
"23503" -> HT.status409 -- foreign_key_violation
|
||||||
|
"23505" -> HT.status409 -- unique_violation
|
||||||
'2':'5':_ -> HT.status500 -- invalid tx state
|
'2':'5':_ -> HT.status500 -- invalid tx state
|
||||||
'2':'8':_ -> HT.status403 -- invalid auth specification
|
'2':'8':_ -> HT.status403 -- invalid auth specification
|
||||||
'2':'D':_ -> HT.status500 -- invalid tx termination
|
'2':'D':_ -> HT.status500 -- invalid tx termination
|
||||||
|
|||||||
@@ -124,6 +124,18 @@ spec struct pool = beforeAll_ resetDb $ around (withApp cfgDefault struct pool)
|
|||||||
it "fails with 400 and error" $
|
it "fails with 400 and error" $
|
||||||
post "/simple_pk" "}{ x = 2" `shouldRespondWith` 400
|
post "/simple_pk" "}{ x = 2" `shouldRespondWith` 400
|
||||||
|
|
||||||
|
context "with valid json payload" $
|
||||||
|
it "succeeds and returns 201 created" $
|
||||||
|
post "/simple_pk" [json| { "k":"k1", "extra":"e1" } |] `shouldRespondWith` 201
|
||||||
|
|
||||||
|
context "attempting to insert a row with the same primary key" $
|
||||||
|
it "fails returning a 409 Conflict" $
|
||||||
|
post "/simple_pk" [json| { "k":"k1", "extra":"e1" } |] `shouldRespondWith` 409
|
||||||
|
|
||||||
|
context "attempting to insert a row with confliting unique constraint" $
|
||||||
|
it "fails returning a 409 Conflict" $
|
||||||
|
post "/withUnique" [json| { "uni":"nodup", "extra":"e2" } |] `shouldRespondWith` 409
|
||||||
|
|
||||||
context "jsonb" $ do
|
context "jsonb" $ do
|
||||||
it "serializes nested object" $ do
|
it "serializes nested object" $ do
|
||||||
let inserted = [json| { "data": { "foo":"bar" } } |]
|
let inserted = [json| { "data": { "foo":"bar" } } |]
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ spec struct pool = around (withApp cfgDefault struct pool) $ do
|
|||||||
, {"schema":"test","name":"users","insertable":true}
|
, {"schema":"test","name":"users","insertable":true}
|
||||||
, {"schema":"test","name":"users_projects","insertable":true}
|
, {"schema":"test","name":"users_projects","insertable":true}
|
||||||
, {"schema":"test","name":"users_tasks","insertable":true}
|
, {"schema":"test","name":"users_tasks","insertable":true}
|
||||||
|
, {"schema":"test","name":"withUnique","insertable":true}
|
||||||
] |]
|
] |]
|
||||||
{matchStatus = 200}
|
{matchStatus = 200}
|
||||||
|
|
||||||
|
|||||||
Vendored
+2
@@ -266,6 +266,8 @@ INSERT INTO "Escap3e;" VALUES (1), (2), (3), (4), (5);
|
|||||||
TRUNCATE TABLE "ghostBusters" CASCADE;
|
TRUNCATE TABLE "ghostBusters" CASCADE;
|
||||||
INSERT INTO "ghostBusters" VALUES (1), (3), (5);
|
INSERT INTO "ghostBusters" VALUES (1), (3), (5);
|
||||||
|
|
||||||
|
TRUNCATE TABLE "withUnique" CASCADE;
|
||||||
|
INSERT INTO "withUnique" VALUES ('nodup', 'blah')
|
||||||
--
|
--
|
||||||
-- PostgreSQL database dump complete
|
-- PostgreSQL database dump complete
|
||||||
--
|
--
|
||||||
|
|||||||
Vendored
+1
@@ -34,6 +34,7 @@ GRANT ALL ON TABLE
|
|||||||
, users_tasks
|
, users_tasks
|
||||||
, "Escap3e;"
|
, "Escap3e;"
|
||||||
, "ghostBusters"
|
, "ghostBusters"
|
||||||
|
, "withUnique"
|
||||||
TO postgrest_test_anonymous;
|
TO postgrest_test_anonymous;
|
||||||
|
|
||||||
GRANT INSERT ON TABLE insertonly TO postgrest_test_anonymous;
|
GRANT INSERT ON TABLE insertonly TO postgrest_test_anonymous;
|
||||||
|
|||||||
Vendored
+5
@@ -599,6 +599,11 @@ CREATE TABLE "ghostBusters" (
|
|||||||
"escapeId" integer not null references "Escap3e;"("so6meIdColumn")
|
"escapeId" integer not null references "Escap3e;"("so6meIdColumn")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE "withUnique" (
|
||||||
|
uni text UNIQUE,
|
||||||
|
extra text
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Name: id; Type: DEFAULT; Schema: test; Owner: -
|
-- Name: id; Type: DEFAULT; Schema: test; Owner: -
|
||||||
|
|||||||
Reference in New Issue
Block a user