Skip to content

Commit

Permalink
Retry on SSL errors (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
amadejkastelic authored Oct 17, 2024
1 parent a2cdb90 commit 7b66584
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion bot/adapters/discord/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,12 +383,16 @@ async def _send_post(
if e.status != 413: # Payload too large
raise e
if post.buffer is not None:
logger.info('File too large, resizing...')
logger.info('File too large, resizing...', size=len(post.buffer))
post.buffer.seek(0)
post.buffer = await utils.resize(buffer=post.buffer, extension=extension)
return await self._send_post(post=post, send_func=send_func, author=author)

raise exceptions.BotError('Failed to send message') from e
except utils.SSL_ERRORS as e:
# Retry on SSL errors
logger.error("SSL Error, retrying", error=str(e))
return await self._send_post(post=post, send_func=send_func, author=author)

async def _send_comments(
self,
Expand Down
8 changes: 8 additions & 0 deletions bot/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@
import typing
from contextlib import contextmanager

import aiohttp
import magic
from PIL import Image as pil_image
from django import db as django_db
from requests import exceptions as requests_exceptions

emoji = ['😼', '😺', '😸', '😹', '😻', '🙀', '😿', '😾', '😩', '🙈', '🙉', '🙊', '😳']

SSL_ERRORS = (
requests_exceptions.SSLError,
aiohttp.ClientSSLError,
aiohttp.ClientConnectorSSLError,
)


def find_first_url(string: str) -> typing.Optional[str]:
urls = re.findall(r'(https?://[^\s]+)', string)
Expand Down

0 comments on commit 7b66584

Please sign in to comment.