From 29505d4a52647a548d3f571dc68c3b9de26b16b1 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Mon, 4 Sep 2023 19:22:06 +0100 Subject: [PATCH] Handle upstream issues with mastodon --- website/well_known/views.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/website/well_known/views.py b/website/well_known/views.py index 066e598..040b720 100644 --- a/website/well_known/views.py +++ b/website/well_known/views.py @@ -8,6 +8,7 @@ from django.utils.decorators import method_decorator from django.views.decorators.cache import cache_control, cache_page from django.views.generic import TemplateView from proxy.views import proxy_view +from requests.exceptions import RequestException from website.contact.models import ContactPage from website.contrib.singleton_page.utils import SingletonPageCache @@ -55,7 +56,10 @@ def activitypub_proxy(request: HttpRequest) -> HttpResponse: if not settings.ACTIVITYPUB_HOST: raise Http404 - return proxy_view( - request, - f"https://{settings.ACTIVITYPUB_HOST}{request.path}", - ) + try: + return proxy_view( + request, + f"https://{settings.ACTIVITYPUB_HOST}{request.path}", + ) + except RequestException: + return HttpResponse(status_code=502)