Also catch URLError in ajax-proxy

fix #1118
This commit is contained in:
Yohan Boniface 2023-06-02 22:36:02 +02:00
parent e1b18c5daf
commit 39a887a6f6

View file

@ -5,6 +5,7 @@ import re
import socket import socket
from datetime import date, timedelta from datetime import date, timedelta
from pathlib import Path from pathlib import Path
from urllib.error import URLError
from django.conf import settings from django.conf import settings
from django.contrib import messages from django.contrib import messages
@ -303,6 +304,8 @@ class AjaxProxy(View):
proxied_request = opener.open(request) proxied_request = opener.open(request)
except HTTPError as e: except HTTPError as e:
return HttpResponse(e.msg, status=e.code, content_type="text/plain") return HttpResponse(e.msg, status=e.code, content_type="text/plain")
except URLError:
return HttpResponseBadRequest("URL error")
else: else:
status_code = proxied_request.code status_code = proxied_request.code
mimetype = proxied_request.headers.get( mimetype = proxied_request.headers.get(