1
0
mirror of https://gitlab.com/brutaldon/brutaldon.git synced 2024-12-04 14:46:24 -05:00

Mastodon.py raises an error when session is expired

Sometimes Brutaldon thinks it has a valid session key, but the upstream Fediverse server does not, and Brutaldon needs to handle that. Brutal probably should un-set its own internal logged-in state when that happens, but for now it just returns the same thing as if you weren't logged into Brutaldon, making you log in again, making Brutaldon get a new session token from upstream.
This commit is contained in:
Cy 2020-06-01 00:21:38 +00:00
parent 00e35409ef
commit dd19608b66
No known key found for this signature in database
GPG Key ID: F66D599380F88521

View File

@ -133,7 +133,7 @@ def br_login_required(function=None, home_url=None, redirect_field_name=None):
def _dec(view_func): def _dec(view_func):
def _view(request, *args, **kwargs): def _view(request, *args, **kwargs):
if not is_logged_in(request): def not_logged_in():
url = None url = None
if redirect_field_name and redirect_field_name in request.REQUEST: if redirect_field_name and redirect_field_name in request.REQUEST:
url = request.REQUEST[redirect_field_name] url = request.REQUEST[redirect_field_name]
@ -142,8 +142,14 @@ def br_login_required(function=None, home_url=None, redirect_field_name=None):
if not url: if not url:
url = "/" url = "/"
return HttpResponseRedirect(url) return HttpResponseRedirect(url)
if not is_logged_in(request):
return not_logged_in()
else: else:
try:
return view_func(request, *args, **kwargs) return view_func(request, *args, **kwargs)
except MastodonAPIError:
# mastodon must have expired our session
return not_logged_in()
_view.__name__ = view_func.__name__ _view.__name__ = view_func.__name__
_view.__dict__ = view_func.__dict__ _view.__dict__ = view_func.__dict__