diff --git a/api/staleness.py b/api/staleness.py index df458bd77..c0969340e 100644 --- a/api/staleness.py +++ b/api/staleness.py @@ -91,9 +91,6 @@ def create_staleness(body): if not get_flag_value(FLAG_INVENTORY_CUSTOM_STALENESS): return Response(None, status.HTTP_501_NOT_IMPLEMENTED) - current_identity = get_current_identity() - org_id = current_identity.org_id - # Validate account staleness input data try: validated_data = StalenessSchema().load(body) @@ -107,9 +104,9 @@ def create_staleness(body): log_create_staleness_succeeded(logger, created_staleness.id) except IntegrityError: - error_message = f"An account staleness with org_id {org_id} already exists." + error_message = f"Staleness record for org_id {get_current_identity().org_id} already exists." - log_create_staleness_failed(logger, org_id) + log_create_staleness_failed(logger, get_current_identity().org_id) logger.exception(error_message) return json_error_response("Integrity error", error_message, status.HTTP_400_BAD_REQUEST) @@ -127,7 +124,10 @@ def delete_staleness(): remove_staleness() return flask_json_response(None, status.HTTP_204_NO_CONTENT) except NoResultFound: - abort(status.HTTP_404_NOT_FOUND, "Account Staleness not found.") + abort( + status.HTTP_404_NOT_FOUND, + f"Staleness record for org_id {get_current_identity().org_id} does not exist.", + ) @api_operation @@ -149,4 +149,7 @@ def update_staleness(body): return flask_json_response(serialize_staleness_response(updated_staleness), status.HTTP_200_OK) except NoResultFound: - abort(status.HTTP_404_NOT_FOUND, "Account Staleness not found.") + abort( + status.HTTP_404_NOT_FOUND, + f"Staleness record for org_id {get_current_identity().org_id} does not exist.", + )