From ad9d3599bccd825fa0f17e0b4334dfcf01e877ef Mon Sep 17 00:00:00 2001 From: Shyam Sunder Date: Wed, 22 Sep 2021 22:08:07 -0400 Subject: [PATCH] server/net: return more useful error messages --- server/szurubooru/func/net.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/server/szurubooru/func/net.py b/server/szurubooru/func/net.py index 9dff3c4..3f085a0 100644 --- a/server/szurubooru/func/net.py +++ b/server/szurubooru/func/net.py @@ -42,10 +42,17 @@ def download(url: str, use_video_downloader: bool = False) -> bytes: while (chunk := handle.read(_dl_chunk_size)) : length_tally += len(chunk) if length_tally > config.config["max_dl_filesize"]: - raise DownloadTooLargeError(url) + raise DownloadTooLargeError( + "Download target exceeds maximum. (%d)" + % (config.config["max_dl_filesize"]), + extra_fields={"URL": url}, + ) content_buffer += chunk except urllib.error.HTTPError as ex: - raise DownloadError(url) from ex + raise DownloadError( + "Download target returned HTTP %d. (%s)" % (ex.code, ex.reason), + extra_fields={"URL": url}, + ) from ex if ( youtube_dl_error @@ -69,7 +76,8 @@ def _get_youtube_dl_content_url(url: str) -> str: ) except subprocess.CalledProcessError: raise errors.ThirdPartyError( - "Could not extract content location from %s" % (url) + "Could not extract content location from URL.", + extra_fields={"URL": url}, ) from None