From fd6d876679062f1a478735b7ba38835adff97152 Mon Sep 17 00:00:00 2001 From: Paul Brussee Date: Fri, 13 May 2016 16:12:23 +0200 Subject: [PATCH] change response code of error to http 500 --- Tribler/Core/Modules/restapi/my_channel_endpoint.py | 1 + .../Test/Core/Modules/RestApi/test_my_channel_endpoints.py | 6 +++--- doc/Tribler REST API.md | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Tribler/Core/Modules/restapi/my_channel_endpoint.py b/Tribler/Core/Modules/restapi/my_channel_endpoint.py index 9895a712cca..1581f948db2 100644 --- a/Tribler/Core/Modules/restapi/my_channel_endpoint.py +++ b/Tribler/Core/Modules/restapi/my_channel_endpoint.py @@ -96,6 +96,7 @@ def render_PUT(self, request): try: channel_id = self.session.create_channel(parameters['name'][0], parameters['description'][0], mode) except DuplicateChannelNameError as ex: + request.setResponseCode(http.INTERNAL_SERVER_ERROR) request.setHeader('Content-Type', 'text/json') return json.dumps({ "error": { diff --git a/Tribler/Test/Core/Modules/RestApi/test_my_channel_endpoints.py b/Tribler/Test/Core/Modules/RestApi/test_my_channel_endpoints.py index 16354974610..b77330a0089 100644 --- a/Tribler/Test/Core/Modules/RestApi/test_my_channel_endpoints.py +++ b/Tribler/Test/Core/Modules/RestApi/test_my_channel_endpoints.py @@ -115,7 +115,7 @@ def verify_channel_created(body): @deferred(timeout=10) def test_my_channel_endpoint_create_duplicate_name_error(self): """ - Testing whether the API returns a formatted 200 error if DuplicateChannelNameError is raised + Testing whether the API returns a formatted 500 error if DuplicateChannelNameError is raised """ def verify_error_message(body): @@ -136,8 +136,8 @@ def verify_error_message(body): } self.session.create_channel = self.create_fake_channel_with_existing_name self.should_check_equality = False - return self.do_request('mychannel', expected_code=200, expected_json=None, request_type='PUT', - post_data=post_data).addCallback(verify_error_message) + return self.do_request('mychannel', expected_code=500, expected_json=None, request_type='PUT', + post_data=post_data).addErrback(verify_error_message) @deferred(timeout=10) def test_my_channel_endpoint_create_no_name_param(self): diff --git a/doc/Tribler REST API.md b/doc/Tribler REST API.md index fa97da77bef..26da14e5aef 100644 --- a/doc/Tribler REST API.md +++ b/doc/Tribler REST API.md @@ -24,7 +24,7 @@ If an unhandled exception occurs the response will have code HTTP 500 and look l } } ``` -If a valid request of a client caused a recoverable error the response will have code HTTP 200 and look like this: +If a valid request of a client caused a recoverable error the response will have code HTTP 500 and look like this: ```json { "error": {