Commit 05e4498a authored by Mihai Patrascoiu's avatar Mihai Patrascoiu
Browse files

FTS-1669: Properly propagate HTTP status code and messages

Ensures the following scenarios work correctly:
- 1 job, successful: 200 OK, job JSON
- 1 job, error: error code, job_error JSON
- multiple jobs, all successful: 200 OK, list of job JSONs
- multiple jobs, at least one error: 207 Multi-Status, list of job and job_error JSONs

Change reflected in functional tests as well
parent 4a55f8d5
Pipeline #2000339 passed with stage
in 2 minutes and 43 seconds
......@@ -193,7 +193,7 @@ class JobsController(BaseController):
Get the job with the given ID
"""
job_ids = job_list.split(',')
multistatus = False
status_error_count = 0
# request is not available inside the generator
environ = request.environ
......@@ -229,13 +229,15 @@ class JobsController(BaseController):
http_status="%s %s" % (e.code, e.title),
http_message=e.detail
))
multistatus = (len(job_ids) > 1)
status_error_count += 1
if len(job_ids) == 1:
if status_error_count == 1:
start_response(statuses[0].get('http_status'), [('Content-Type', 'application/json')])
return statuses[0]
if multistatus:
elif status_error_count > 0:
start_response('207 Multi-Status', [('Content-Type', 'application/json')])
return statuses
@doc.response(403, 'The user doesn\'t have enough privileges')
......
......@@ -95,9 +95,12 @@ class TestJobListing(TestController):
url="/jobs/1234x",
status=404
).json
error_message = json.loads(error['message'])
self.assertEquals(error['status'], '404 Not Found')
self.assertEquals(error['message'], 'No job with the id "1234x" has been found')
self.assertEquals(error_message['job_id'], '1234x')
self.assertEquals(error_message['http_status'], '404 Not Found')
self.assertEquals(error_message['http_message'], 'No job with the id "1234x" has been found')
def test_list_job_default(self):
"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment