Skip to content

Commit 5df16b0

Browse files
committed
Catch all errors in external URL uploads
1 parent 97ad6fe commit 5df16b0

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

mautrix/client/api/modules/media_repository.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,18 +290,23 @@ async def _upload_to_url(
290290
backoff = 4
291291
while True:
292292
self.log.debug("Uploading media to external URL %s", upload_url)
293-
upload_response = await self.api.session.put(upload_url, data=data, headers=headers)
294-
if not upload_response.ok:
293+
upload_response = None
294+
try:
295+
upload_response = await self.api.session.put(
296+
upload_url, data=data, headers=headers
297+
)
298+
upload_response.raise_for_status()
299+
except Exception as e:
295300
if retry_count == 0:
296301
raise make_request_error(
297-
http_status=upload_response.status,
298-
text=await upload_response.text(),
302+
http_status=upload_response.status if upload_response else -1,
303+
text=(await upload_response.text()) if upload_response else "",
299304
errcode="COM.BEEPER.EXTERNAL_UPLOAD_ERROR",
300305
message=None,
301306
)
302307
self.log.warning(
303-
f"Uploading media to external URL {upload_url} failed with HTTP "
304-
f"{upload_response.status}, retrying in {backoff} seconds"
308+
f"Uploading media to external URL {upload_url} failed: {e}, "
309+
f"retrying in {backoff} seconds",
305310
)
306311
await asyncio.sleep(backoff)
307312
backoff *= 2

0 commit comments

Comments
 (0)