From 0a8cb8f1d574b2f691ac92e489f2fc7a4123ddf9 Mon Sep 17 00:00:00 2001 From: Aadesh-Baral Date: Tue, 29 Aug 2023 13:56:05 +0545 Subject: [PATCH] Remove nerver reaching except blocks. --- backend/api/projects/teams.py | 17 +++++++---------- backend/api/tasks/actions.py | 11 +---------- backend/services/mapping_service.py | 4 ---- 3 files changed, 8 insertions(+), 24 deletions(-) diff --git a/backend/api/projects/teams.py b/backend/api/projects/teams.py index e75fe06fbd..fc88df55f1 100644 --- a/backend/api/projects/teams.py +++ b/backend/api/projects/teams.py @@ -2,7 +2,7 @@ from schematics.exceptions import DataError from backend.exceptions import Forbidden -from backend.services.team_service import TeamService, TeamServiceError +from backend.services.team_service import TeamService from backend.services.project_admin_service import ProjectAdminService from backend.services.project_service import ProjectService from backend.services.users.authentication_service import token_auth @@ -180,16 +180,13 @@ def patch(self, team_id, project_id): current_app.logger.error(f"Error validating request: {str(e)}") return {"Error": str(e), "SubCode": "InvalidData"}, 400 - try: - if not ProjectAdminService.is_user_action_permitted_on_project( - token_auth.current_user, project_id - ): - raise Forbidden(sub_code="USER_NOT_PROJECT_MANAGER") + if not ProjectAdminService.is_user_action_permitted_on_project( + token_auth.current_user, project_id + ): + raise Forbidden(sub_code="USER_NOT_PROJECT_MANAGER") - TeamService.change_team_role(team_id, project_id, role) - return {"Status": "Team role updated successfully."}, 200 - except TeamServiceError as e: - return str(e), 402 # FLAGGED FOR STATUS CODE/UNREACHABLE + TeamService.change_team_role(team_id, project_id, role) + return {"Status": "Team role updated successfully."}, 200 @token_auth.login_required def delete(self, team_id, project_id): diff --git a/backend/api/tasks/actions.py b/backend/api/tasks/actions.py index 017dc8e0f9..16741a99d6 100644 --- a/backend/api/tasks/actions.py +++ b/backend/api/tasks/actions.py @@ -1,7 +1,7 @@ from flask_restful import Resource, current_app, request from schematics.exceptions import DataError -from backend.exceptions import NotFound, Forbidden +from backend.exceptions import Forbidden from backend.models.dtos.grid_dto import SplitTaskDTO from backend.models.postgis.utils import InvalidGeoJson from backend.services.grid.split_service import SplitService, SplitServiceError @@ -262,15 +262,6 @@ def post(self, project_id, task_id): return task.to_primitive(), 200 except MappingServiceError as e: return {"Error": str(e).split("-")[1], "SubCode": str(e).split("-")[0]}, 409 - except NotFound as e: # FLAGGED IF THIS CATCH IS NEEDED - return e.to_dict() - except Exception as e: # FLAGGED IF THIS CATCH IS NEEDED - error_msg = f"Task Lock API - unhandled error: {str(e)}" - current_app.logger.critical(error_msg) - return { - "Error": "Task unlock failed", - "SubCode": "InternalServerError", - }, 500 finally: # Refresh mapper level after mapping UserService.check_and_update_mapper_level(authenticated_user_id) diff --git a/backend/services/mapping_service.py b/backend/services/mapping_service.py index 4b2570cb6c..2a5c362c7c 100644 --- a/backend/services/mapping_service.py +++ b/backend/services/mapping_service.py @@ -198,10 +198,6 @@ def get_task_locked_by_user(project_id: int, task_id: int, user_id: int) -> Task :raises: MappingServiceError """ task = MappingService.get_task(task_id, project_id) - if task is None: # FLAGGED: CHECK IF THIS CONDITION IS EVER REACHED - raise NotFound( - sub_code="TASK_NOT_FOUND", project_id=project_id, task_id=task_id - ) current_state = TaskStatus(task.task_status) if current_state != TaskStatus.LOCKED_FOR_MAPPING: raise MappingServiceError(