2020-05-05 23:50:48 +08:00
|
|
|
from django.http import HttpResponse
|
|
|
|
import functools
|
|
|
|
from django.shortcuts import render
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
from requests.exceptions import Timeout
|
|
|
|
|
|
|
|
|
|
|
|
def mastodon_request_included(func):
|
2023-01-11 19:11:31 -05:00
|
|
|
"""Handles timeout exception of requests to mastodon, returns http 500"""
|
|
|
|
|
2020-05-05 23:50:48 +08:00
|
|
|
@functools.wraps(func)
|
|
|
|
def wrapper(*args, **kwargs):
|
|
|
|
try:
|
|
|
|
return func(*args, **kwargs)
|
2020-10-22 21:45:05 +02:00
|
|
|
except (Timeout, ConnectionError):
|
2020-05-05 23:50:48 +08:00
|
|
|
return render(
|
2023-01-11 19:11:31 -05:00
|
|
|
args[0], "common/error.html", {"msg": _("联邦网络请求超时叻_(´ཀ`」 ∠)__ ")}
|
2020-05-05 23:50:48 +08:00
|
|
|
)
|
2023-01-11 19:11:31 -05:00
|
|
|
|
2020-05-05 23:50:48 +08:00
|
|
|
return wrapper
|
|
|
|
|
|
|
|
|
|
|
|
class HttpResponseInternalServerError(HttpResponse):
|
|
|
|
status_code = 500
|