Handle feature_set errors automatically

Recreate the mastodon object if there's an error complaining about a missing feature set. Only happens for status_post I think. Could be further generalized...
This commit is contained in:
Cy 2020-05-30 23:06:28 +00:00
parent 2dfdb0b859
commit 12d7b4cb7d
No known key found for this signature in database
GPG Key ID: F66D599380F88521
1 changed files with 28 additions and 22 deletions

View File

@ -16,6 +16,7 @@ from brutaldon.forms import (
from brutaldon.models import Client, Account, Preference, Theme
from mastodon import (
Mastodon,
MastodonIllegalArgumentError,
AttribAccessDict,
MastodonError,
MastodonAPIError,
@ -83,7 +84,7 @@ def get_usercontext(request, feature_set="mainline"):
Account.MultipleObjectsReturned,
):
raise NotLoggedInException()
mastodon = get_mastodon()Mastodon(
mastodon = Mastodon(
client_id=client.client_id,
client_secret=client.client_secret,
access_token=user.access_token,
@ -810,6 +811,7 @@ def settings(request):
)
def status_post(account, request, mastodon, **kw):
while True:
try:
mastodon.status_post(**kw)
except MastodonIllegalArgumentError as e:
@ -820,10 +822,14 @@ def status_post(account, request, mastodon, **kw):
account, mastodon = get_usercontext(request,
feature_set=feature_set)
return status_post(account, request, mastodon, **kw)
continue
except TypeError:
# not sure why, but the old code retried status_post without a
# content_type keyword, if there was a TypeError
kw.pop("content_type")
return status_post(account, request, mastodon, **kw)
continue
else:
break
return account, mastodon
@never_cache
@ -888,7 +894,7 @@ def toot(request, mention=None):
].source.privacy
try:
status_post(
account, mastodon,
account, request, mastodon,
status=form.cleaned_data["status"],
visibility=form.cleaned_data["visibility"],
spoiler_text=form.cleaned_data["spoiler_text"],