Skip to content
Snippets Groups Projects
Commit 759e4a6c authored by Rajmund Hruška's avatar Rajmund Hruška
Browse files

Server: Improve error messages

parent 8b6b3296
Branches
No related tags found
No related merge requests found
......@@ -230,7 +230,8 @@ class Warden3ServerTest(unittest.TestCase):
("/sendEvents?secret=abc", '[{"Node": [{"Name"}]}]', "400 Deserialization error.", None),
("/sendEvents?secret=abc", '[{"Node": [{"Name": "test"}]}]', "422 Node does not correspond with saving client", None),
("/sendEvents?secret=abc", '[{"Node": [{"Name": "cz.cesnet.warden3test"}], "ID" : "120820201142"}]', "200 OK", ['{"saved": 1}']),
("/sendEvents?secret=abc", '[{"Node": [{"Name": "cz.cesnet.warden3test"}], "ID" : "120820201142"}]', "400 IdeaID is not unique", None),
("/sendEvents?secret=abc", '[{"Node": [{"Name": "cz.cesnet.warden3test"}], "ID" : "120820201142"}]', "409 IDEA event with this ID already exists", None),
("/sendEvents?secret=abc", '[{"Node": [{"Name": "cz.cesnet.warden3test"}], "ID" : "120820201143"}]', "200 OK", None),
]
for query, payload, expected_status, expected_response in tests:
with self.subTest(query=query, payload=payload, expected_status=expected_status, expected_response=expected_response):
......
......@@ -767,9 +767,9 @@ class MySQL(ObjectBase):
try:
ideaid = event['ID']
except (KeyError, TypeError, ValueError):
exception = self.req.error(message="IDEA ID is null", error=400, exc=sys.exc_info(), env=self.req.env)
exception = self.req.error(message="Missing IDEA ID", error=400, exc=sys.exc_info(), env=self.req.env)
exception.log(self.log)
errors.extend([{"error": 400, "message": "IDEA ID is not present"}])
errors.extend([{"error": 400, "message": "Missing IDEA ID"}])
error_indx.append(event_id)
continue
lastid = db.query(
......@@ -791,11 +791,10 @@ class MySQL(ObjectBase):
db.query("INSERT INTO event_tag_mapping (event_id,tag_id) VALUES (%s, %s)", (lastid, tag_id))
# In the future there may be other integrity errors, but at the moment there is just uniqueness of idea_id
except my.IntegrityError as e:
exception = self.req.error(message="Database integrity error", error=400, exc=sys.exc_info(), env=self.req.env)
exception = self.req.error(message="IDEA event with this ID already exists", error=400, exc=sys.exc_info(), env=self.req.env)
exception.log(self.log)
errors.extend([{"error": 400, "message": "IDEA ID is not unique"}])
errors.extend([{"error": 409, "message": "IDEA event with this ID already exists"}])
error_indx.append(event_id)
pass
return (errors, error_indx)
except Exception as e:
exception = self.req.error(message="DB error", error=500, exc=sys.exc_info(), env=self.req.env)
......@@ -1134,7 +1133,7 @@ class WardenHandler(ObjectBase):
return []
def add_event_nums(self, ilist, events, errlist):
"""Uniquify the list of errors and append the lists of indices and ids of events affected by the error."""
"""Uniquify the list of errors and append the lists of indices and add ids of events affected by the error."""
if not ilist:
return errlist
unique_errors = [dict(s) for s in set(frozenset(d.items()) for d in errlist)]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment