Skip to content
Snippets Groups Projects
Commit bad02d336ca6 authored by Denis Laxalde's avatar Denis Laxalde
Browse files

Set status code to 500 for "generic" exception

In many cases, such errors would occur for an internal reason not because of
an invalid request. So prefer "500 Internal Server Error" over "400 Bad
Request" which might be misleading if the error is actually "internal".

Later on, we should make a proper distinction between true internal errors and
*currently unhandled* client errors. One such case concerns converting
TypeResolverException that might occur when setting a relation to a bad target
into a proper Bad Request (hence the "TODO" in respective test).
parent 67c1b0874683
No related branches found
No related tags found
No related merge requests found
......@@ -359,7 +359,7 @@
detail = str(exc)
if detail:
kwargs['detail'] = detail
return json_problem(status=400, **kwargs)
return json_problem(status=500, **kwargs)
def includeme(config):
......
......@@ -144,7 +144,8 @@
cwuser_eid = cnx.find('CWUser', login=u'admin')[0][0]
self.login()
url = '/book/%s/author' % book.eid
self.webapp.post_json(url, [str(cwuser_eid)], status=400,
# TODO: status should be 4xx
self.webapp.post_json(url, [str(cwuser_eid)], status=500,
headers={'accept': 'application/json'})
def test_put_with_incomplete_data(self):
......@@ -345,7 +346,7 @@
error = ValueError("invalid literal for int() with base 10: 'foo'")
with patch('cubicweb.req.RequestSessionBase.create_entity',
side_effect=error):
res = self.webapp.post_json('/cwuser/', data, status=400,
res = self.webapp.post_json('/cwuser/', data, status=500,
headers={'Accept': 'application/json'})
self.assertEqual(res.content_type, 'application/problem+json')
self.assertEqual(res.json_body, {
......@@ -349,8 +350,8 @@
headers={'Accept': 'application/json'})
self.assertEqual(res.content_type, 'application/problem+json')
self.assertEqual(res.json_body, {
u'status': 400,
u'title': u'Bad Request',
u'status': 500,
u'title': u'Internal Server Error',
u'detail': u"invalid literal for int() with base 10: 'foo'",
})
......@@ -360,7 +361,7 @@
with patch('cubicweb.req.RequestSessionBase.create_entity',
side_effect=NotImplementedError()):
res = self.webapp.post_json('/book/', data, status=400,
res = self.webapp.post_json('/book/', data, status=500,
headers={'Accept': 'application/json'})
self.assertEqual(res.content_type, 'application/problem+json')
self.assertEqual(res.json_body, {
......@@ -364,8 +365,8 @@
headers={'Accept': 'application/json'})
self.assertEqual(res.content_type, 'application/problem+json')
self.assertEqual(res.json_body, {
u'status': 400,
u'title': u'Bad Request',
u'status': 500,
u'title': u'Internal Server Error',
})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment