From 65ecaa8c5a845022ae19e4d90ec880c498b17e0b Mon Sep 17 00:00:00 2001 From: roberto Date: Thu, 2 Jul 2020 15:58:14 -0500 Subject: [PATCH] fix: :goal_net: return 204 when time-entry not found in running --- time_tracker_api/time_entries/time_entries_model.py | 5 ++++- time_tracker_api/time_entries/time_entries_namespace.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/time_tracker_api/time_entries/time_entries_model.py b/time_tracker_api/time_entries/time_entries_model.py index 11126b17..440bc95f 100644 --- a/time_tracker_api/time_entries/time_entries_model.py +++ b/time_tracker_api/time_entries/time_entries_model.py @@ -310,7 +310,10 @@ def find_running( ) function_mapper = self.get_mapper_or_dict(mapper) - return function_mapper(next(result)) + try: + return function_mapper(next(result)) + except StopIteration as no_result: + raise CustomError(HTTPStatus.NO_CONTENT) def validate_data(self, data, event_context: EventContext): start_date = data.get('start_date') diff --git a/time_tracker_api/time_entries/time_entries_namespace.py b/time_tracker_api/time_entries/time_entries_namespace.py index 5a69b938..1876a154 100644 --- a/time_tracker_api/time_entries/time_entries_namespace.py +++ b/time_tracker_api/time_entries/time_entries_namespace.py @@ -292,7 +292,7 @@ def post(self, id): @ns.route('/running') @ns.response(HTTPStatus.OK, 'The time entry that is active: currently running') -@ns.response(HTTPStatus.NOT_FOUND, 'There is no time entry running right now') +@ns.response(HTTPStatus.NO_CONTENT, 'There is no time entry running right now') class ActiveTimeEntry(Resource): @ns.doc('running_time_entry') @ns.marshal_with(time_entry)