From b5db41920f878e9f29fffd05480a3d468987ebbc Mon Sep 17 00:00:00 2001 From: Evan Cordell Date: Mon, 11 Apr 2016 16:34:40 -0400 Subject: [PATCH] Address review comments --- endpoints/api/__init__.py | 3 +-- endpoints/api/discovery.py | 12 ++++++++---- endpoints/api/error.py | 3 +-- endpoints/exception.py | 12 +++++------- test/test_api_usage.py | 2 +- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/endpoints/api/__init__.py b/endpoints/api/__init__.py index eca01e5ee..8045b0f1d 100644 --- a/endpoints/api/__init__.py +++ b/endpoints/api/__init__.py @@ -316,8 +316,7 @@ def request_error(exception=None, **kwargs): message = 'Request error.' if exception: message = exception.message - if 'message' in data.keys(): - message = data.pop('message') + message = data.pop('message', message) raise InvalidRequest(message, data) diff --git a/endpoints/api/discovery.py b/endpoints/api/discovery.py index 6ed99b154..b66bef698 100644 --- a/endpoints/api/discovery.py +++ b/endpoints/api/discovery.py @@ -183,16 +183,20 @@ def swagger_route_data(include_internal=False, compact=False): 'type': 'object', 'properties': { 'status': { - 'type': 'integer' + 'type': 'integer', + 'description': 'Status code of the response.' }, 'type': { - 'type': 'string' + 'type': 'string', + 'description': 'Reference to the type of the error.' }, 'detail': { - 'type': 'string' + 'type': 'string', + 'description': 'Details about the specific instance of the error.' }, 'title': { - 'type': 'string' + 'type': 'string', + 'description': 'Unique error code to identify the type of error.' } }, 'required': [ diff --git a/endpoints/api/error.py b/endpoints/api/error.py index 416defcd8..c11623cd4 100644 --- a/endpoints/api/error.py +++ b/endpoints/api/error.py @@ -51,6 +51,5 @@ class Error(ApiResource): """ Get a detailed description of the error """ if error_type in ERROR_DESCRIPTION.keys(): return error_view(error_type), 200 - else: - raise NotFound() + raise NotFound() diff --git a/endpoints/exception.py b/endpoints/exception.py index 49796e62a..098e9ba12 100644 --- a/endpoints/exception.py +++ b/endpoints/exception.py @@ -34,19 +34,19 @@ ERROR_DESCRIPTION = { class ApiException(Exception): """ - o "type" (string) - A URI reference that identifies the + - "type" (string) - A URI reference that identifies the problem type. - o "title" (string) - A short, human-readable summary of the problem + - "title" (string) - A short, human-readable summary of the problem type. It SHOULD NOT change from occurrence to occurrence of the problem, except for purposes of localization - o "status" (number) - The HTTP status code + - "status" (number) - The HTTP status code - o "detail" (string) - A human-readable explanation specific to this + - "detail" (string) - A human-readable explanation specific to this occurrence of the problem. - o "instance" (string) - A URI reference that identifies the specific + - "instance" (string) - A URI reference that identifies the specific occurrence of the problem. It may or may not yield further information if dereferenced. """ @@ -58,8 +58,6 @@ class ApiException(Exception): self.payload = payload self.error_type = error_type - print(self) - def to_dict(self): rv = dict(self.payload or ()) diff --git a/test/test_api_usage.py b/test/test_api_usage.py index 2ff4cd1b5..66e24df22 100644 --- a/test/test_api_usage.py +++ b/test/test_api_usage.py @@ -285,7 +285,7 @@ class TestUserStarredRepositoryList(ApiTestCase): }, expected_code=401) - def test_star_and_uznstar_repo_user(self): + def test_star_and_unstar_repo_user(self): self.login(READ_ACCESS_USER) # Queries: Base + the list query