Skip to content

Commit

Permalink
Try-except in requests.get
Browse files Browse the repository at this point in the history
  • Loading branch information
magnified103 committed Oct 14, 2024
1 parent 1a4fd73 commit 7b95b0b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions judge/views/problem_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from django.views.decorators.csrf import csrf_exempt
from django.views.generic import FormView
from django.views.generic.list import BaseListView
from requests.exceptions import HTTPError
from requests.exceptions import HTTPError, RequestException
from reversion import revisions

from judge.models import Language, Problem, ProblemExportKey, ProblemGroup, ProblemType
Expand Down Expand Up @@ -204,10 +204,13 @@ def form_valid(self, form):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['host_url'] = settings.VNOJ_PROBLEM_IMPORT_HOST
response = requests.get(get_problem_export_url(), timeout=settings.VNOJ_PROBLEM_IMPORT_TIMEOUT)
context['status'] = response.ok
if response.ok:
context['remaining_uses'] = response.json().get('remaining_uses')
try:
response = requests.get(get_problem_export_url(), timeout=settings.VNOJ_PROBLEM_IMPORT_TIMEOUT)
context['status'] = response.ok
if response.ok:
context['remaining_uses'] = response.json().get('remaining_uses')
except RequestException:
context['status'] = False
return context

def dispatch(self, request, *args, **kwargs):
Expand Down

0 comments on commit 7b95b0b

Please sign in to comment.