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

FIX#4259 : Add better error handling for getting AWS credentials for a challenge #4334

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 29 additions & 17 deletions apps/challenges/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2830,25 +2830,37 @@ def get_aws_credentials_for_participant_team(request, phase_pk):
- When participant_team has not participanted in challenge
- When Challenge is not Docker based
"""
challenge_phase = get_challenge_phase_model(phase_pk)
challenge = challenge_phase.challenge
participant_team = get_participant_team_of_user_for_a_challenge(
request.user, challenge.pk
)
if not challenge.is_docker_based:
response_data = {
"error": "Sorry, this is not a docker based challenge."
}
return Response(response_data, status=status.HTTP_400_BAD_REQUEST)
try:
challenge_phase = get_challenge_phase_model(phase_pk)
if not challenge_phase:
return Response({"error": f"An error occurred while retrieving the challenge phase with ID {phase_pk}"}, status=status.HTTP_400_BAD_REQUEST)

if participant_team is None:
response_data = {
"error": "You have not participated in this challenge."
}
challenge = challenge_phase.challenge
try:
participant_team = get_participant_team_of_user_for_a_challenge(
request.user, challenge.pk
)
except Exception:
return Response({"error": "An error occurred while retrieving the participant team"}, status=status.HTTP_400_BAD_REQUEST)
if not challenge.is_docker_based:
response_data = {
"error": "Sorry, this is not a docker based challenge."
}
return Response(response_data, status=status.HTTP_400_BAD_REQUEST)

if participant_team is None:
response_data = {
"error": "You have not participated in this challenge."
}
return Response(response_data, status=status.HTTP_400_BAD_REQUEST)
data = get_aws_credentials_for_submission(challenge, participant_team)
if not data:
return Response({"error": f"An error occurred while retrieving the AWS credentials for challenge {challenge.id} and participant team {participant_team.id}"}, status=status.HTTP_400_BAD_REQUEST)
response_data = {"success": data}
return Response(response_data, status=status.HTTP_200_OK)
except Exception:
response_data = {"error": "There was an unexpected error."}
return Response(response_data, status=status.HTTP_400_BAD_REQUEST)
data = get_aws_credentials_for_submission(challenge, participant_team)
response_data = {"success": data}
return Response(response_data, status=status.HTTP_200_OK)


@api_view(["POST"])
Expand Down