Norse-IoT / niotbot

Norse IoT Discord Bot - Posts to social media
MIT License
1 stars 1 forks source link

Handle errors in scheduled tasks #6

Open zsarge opened 3 hours ago

zsarge commented 3 hours ago

I think when this function ran:

https://github.com/Norse-IoT/niotbot/blob/499261a55c719211966ec3e038792b42a882b838/modules/publish_manager.py#L40-L43

I got this error:

2024-10-02T16:00:09 UTC discord.ext.tasks [ERROR] Unhandled exception in internal background task 'every_day'.
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/instagrapi/mixins/private.py", line 359, in _send_private_request
    response.raise_for_status()
  File "/usr/local/lib/python3.12/site-packages/requests/models.py", line 1024, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://i.instagram.com/api/v1/accounts/login/

During handling of the above exception, another exception occurred:

but then the function never ran again. So, we should probably handle that better

zsarge commented 3 hours ago

We probably want something like:

from requests.exceptions import HTTPError
# ...
try:
     self.log.debug("automatic trigger!") 
     await self.post_approved_submissions() 
except HTTPError:
    # error