Handle 422 errors differently

This commit is contained in:
jeancf 2023-07-18 16:22:05 +02:00
parent 0bee03dd56
commit 9231a78881

View File

@ -1219,10 +1219,12 @@ def main(argv):
toot = mastodon.status_post(tweet['tweet_text'], replied_to_toot, media_ids=media_ids)
except MastodonAPIError as e:
logging.debug('PROBING DETAILS OF MastodonAPIError')
logging.debug(e.args)
logging.debug(e.__notes__)
# Assuming this is an:
_, _, _, exception_message = e.args
if 'Text character limit' in exception_message:
# ERROR (('Mastodon API returned error', 422, 'Unprocessable Entity', 'Validation failed: Text character limit of 500 exceeded'))
logging.error('Tweet text too long: %s characters', str(len(tweet['tweet_text'])))
shutdown(-1)
elif 'Try again in a moment' in exception_message:
# ERROR ('Mastodon API returned error', 422, 'Unprocessable Entity', 'Cannot attach files that have not finished processing. Try again in a moment!')
logging.warning('Mastodon API Error 422: Cannot attach files that have not finished processing. Waiting 30 seconds and retrying.')
# Wait 30 seconds