diff --git a/app/api/alpha/views.py b/app/api/alpha/views.py index d0a93d86..a00dae5e 100644 --- a/app/api/alpha/views.py +++ b/app/api/alpha/views.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from app import cache, db from app.constants import * from app.models import Community, CommunityMember, Post, PostReply, PostVote, User diff --git a/app/utils.py b/app/utils.py index 4b39a7a8..ef022242 100644 --- a/app/utils.py +++ b/app/utils.py @@ -102,14 +102,14 @@ def get_request(uri, params=None, headers=None) -> httpx.Response: response = httpx_client.get(uri, params=payload_str, headers=headers, timeout=timeout * 2, follow_redirects=True) except Exception as e: current_app.logger.info(f"{uri} {connection_error}") - raise httpx_client.ReadError from connection_error + raise httpx_client.ReadError(f"HTTPReadError: {str(e)}") from connection_error except httpx.HTTPError as read_timeout: try: # retry, this time with a longer timeout sleep(random.randint(3, 10)) response = httpx_client.get(uri, params=payload_str, headers=headers, timeout=timeout * 2, follow_redirects=True) except Exception as e: current_app.logger.info(f"{uri} {read_timeout}") - raise httpx.HTTPError from read_timeout + raise httpx.HTTPError(f"HTTPError: {str(e)}") from read_timeout return response @@ -124,7 +124,7 @@ def head_request(uri, params=None, headers=None) -> httpx.Response: response = httpx_client.head(uri, params=params, headers=headers, timeout=5, allow_redirects=True) except httpx.HTTPError as er: current_app.logger.info(f"{uri} {er}") - raise httpx.HTTPError from er + raise httpx.HTTPError(f"HTTPError: {str(er)}") from er return response diff --git a/pyfedi.py b/pyfedi.py index c93b6f96..55132492 100644 --- a/pyfedi.py +++ b/pyfedi.py @@ -24,7 +24,7 @@ def app_context_processor(): def getmtime(filename): return os.path.getmtime('app/static/' + filename) return dict(getmtime=getmtime, instance_domain=current_app.config['SERVER_NAME'], debug_mode=current_app.debug, - arrow=arrow, locale=g.locale, + arrow=arrow, locale=g.locale if hasattr(g, 'locale') else None, POST_TYPE_LINK=POST_TYPE_LINK, POST_TYPE_IMAGE=POST_TYPE_IMAGE, POST_TYPE_ARTICLE=POST_TYPE_ARTICLE, POST_TYPE_VIDEO=POST_TYPE_VIDEO, POST_TYPE_POLL=POST_TYPE_POLL, SUBSCRIPTION_MODERATOR=SUBSCRIPTION_MODERATOR, SUBSCRIPTION_MEMBER=SUBSCRIPTION_MEMBER,