Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardized error messages #45

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/regtech_cleanup_api/routers/cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def delete_all_things(request: Request, lei: str):
if not is_valid_cleanup_lei(lei):
raise RegTechHttpException(
HTTPStatus.NOT_ACCEPTABLE,
name="Not Test LEI",
detail=f"{lei} not valid test lei.",
name="Invalid LEI",
detail=f"Not a valid LEI {lei}",
)
else:
institution_delete_helper(lei, request.state.institution_db_session)
Expand Down
20 changes: 10 additions & 10 deletions src/regtech_cleanup_api/routers/filing_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def delete_filing(request: Request, lei: str, period_code: str):
raise RegTechHttpException(
status_code=HTTPStatus.NOT_ACCEPTABLE,
name="Invalid LEI",
detail="Not a valid LEI",
detail=f"Not a valid LEI {lei}",
)
else:
try:
Expand All @@ -57,7 +57,7 @@ def delete_helper(lei: str, period_code: str, session: Session):
raise RegTechHttpException(
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
name="Contact Info Delete Failed",
detail="Failed to delete contact info",
detail=f"Failed to delete contact info for LEI {lei}",
) from e

try:
Expand All @@ -66,7 +66,7 @@ def delete_helper(lei: str, period_code: str, session: Session):
raise RegTechHttpException(
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
name="Missing User Action Data",
detail="Failed to get user action data",
detail=f"Failed to get user action data for LEI {lei}",
) from e

try:
Expand All @@ -75,7 +75,7 @@ def delete_helper(lei: str, period_code: str, session: Session):
raise RegTechHttpException(
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
name="Submission Delete Failed",
detail="Failed to delete submission data",
detail=f"Failed to delete submission data for LEI {lei}",
) from e

try:
Expand All @@ -84,7 +84,7 @@ def delete_helper(lei: str, period_code: str, session: Session):
raise RegTechHttpException(
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
name="Filing Delete Failed",
detail="Failed to delete filing data",
detail=f"Failed to delete filing data for LEI {lei}",
) from e

try:
Expand All @@ -93,7 +93,7 @@ def delete_helper(lei: str, period_code: str, session: Session):
raise RegTechHttpException(
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
name="User Action Delete Failed",
detail="Failed to delete user action data",
detail=f"Failed to delete user action data for LEI {lei}",
) from e

delete_from_storage(period_code, lei)
Expand All @@ -112,23 +112,23 @@ def delete_submissions(request: Request, lei: str, period_code: str):
raise RegTechHttpException(
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
name="Missing User Action Data",
detail="Failed to get user action data",
detail=f"Failed to get user action data for LEI {lei}",
) from e
try:
repo.delete_submissions(session, lei, period_code)
except Exception as e:
raise RegTechHttpException(
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
name="Submission Delete Failed",
detail="Failed to delete submission data",
detail=f"Failed to delete submission data for LEI {lei}",
) from e
try:
repo.delete_user_actions(session, user_action_ids)
except Exception as e:
raise RegTechHttpException(
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
name="User Action Delete Failed",
detail="Failed to delete user action data",
detail=f"Failed to delete user action data for LEI {lei}",
) from e

delete_from_storage(period_code, lei)
Expand All @@ -139,6 +139,6 @@ def delete_submissions(request: Request, lei: str, period_code: str):
raise RegTechHttpException(
status_code=HTTPStatus.NOT_ACCEPTABLE,
name="Invalid LEI",
detail="Not a valid LEI",
detail=f"Not a valid LEI {lei}",
)
return Response(status_code=status.HTTP_202_ACCEPTED)
12 changes: 6 additions & 6 deletions src/regtech_cleanup_api/routers/institution_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def delete_institution(request: Request, lei: str):
if not is_valid_cleanup_lei(lei):
raise RegTechHttpException(
HTTPStatus.NOT_ACCEPTABLE,
name="Not Test LEI",
detail=f"{lei} not valid test lei.",
name="Invalid LEI",
detail=f"Not a valid LEI {lei}",
)
else:
return delete_helper(lei, request.state.db_session)
Expand All @@ -59,17 +59,17 @@ def delete_helper(lei: str, session: Session):
if not res:
raise RegTechHttpException(
HTTPStatus.NOT_FOUND,
name="Institution to be deleted Not Found",
detail=f"{lei} not found.",
name="Institution Delete Failed",
detail=f"Institution LEI {lei} not found.",
)
else:
try:
oauth2_admin.delete_group(lei)
except Exception:
raise RegTechHttpException(
HTTPStatus.NOT_FOUND,
name="Group Not Found",
detail=f"The group to be deleted {lei} not found.",
name="Group Delete Failed",
detail=f"The group associated with LEI {lei} not found.",
)

return Response(status_code=status.HTTP_204_NO_CONTENT)
2 changes: 1 addition & 1 deletion src/regtech_cleanup_api/services/cleanup_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ def delete_from_storage(period_code: str, lei: str) -> None:
except Exception as e:
raise RegTechHttpException(
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
name="Delete Failure",
name="File Delete Failure",
detail=f"Failed to delete file(s) for LEI {lei}",
) from e
2 changes: 1 addition & 1 deletion tests/services/test_cleanup_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ def test_delete_failure(mocker: MockerFixture):
with pytest.raises(Exception) as e:
cleanup_processor.delete_from_storage("test_period", "test")
assert isinstance(e.value, RegTechHttpException)
assert e.value.name == "Delete Failure"
assert e.value.name == "File Delete Failure"