From 277e712449a36706025a1fdd4f294f2427f03b4a Mon Sep 17 00:00:00 2001 From: cquest Date: Tue, 7 Jun 2016 06:38:07 +0200 Subject: [PATCH] return error 409 when attempting to create duplicates --- backend.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/backend.py b/backend.py index eaf9bb7..73a36f9 100644 --- a/backend.py +++ b/backend.py @@ -262,8 +262,11 @@ class EventResource(BaseEvent): cur.close() db.close() # send back to client - resp.body = """{"id":"%s"}""" % (e[0]) - resp.status = falcon.HTTP_201 + if e is None: + resp.status = falcon.HTTP_409 + else: + resp.body = """{"id":"%s"}""" % (e[0]) + resp.status = falcon.HTTP_201 def on_post(self, req, resp): self.insert_or_update(req, resp, None, """INSERT INTO events ( events_type, events_what, events_when, events_tags, events_geo) VALUES (%s, %s, tstzrange(%s,%s,%s) , %s, %s) RETURNING events_id;""")