Skip to content

Commit

Permalink
Remove nerver reaching except blocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aadesh-Baral committed Aug 29, 2023
1 parent fbe545c commit 0a8cb8f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 24 deletions.
17 changes: 7 additions & 10 deletions backend/api/projects/teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
11 changes: 1 addition & 10 deletions backend/api/tasks/actions.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions backend/services/mapping_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 0a8cb8f

Please sign in to comment.