diff options
Diffstat (limited to 'src/discord_image_bridge')
| -rw-r--r-- | src/discord_image_bridge/utils.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/discord_image_bridge/utils.py b/src/discord_image_bridge/utils.py index e92ed5b..f937997 100644 --- a/src/discord_image_bridge/utils.py +++ b/src/discord_image_bridge/utils.py @@ -11,9 +11,15 @@ from . import fsmanager def download_and_cache(url, filename): cherrypy.log("Downloading attachment %s"%filename) - resp=requests.get(url) - if resp.status_code==200: - hash=do_hash(resp.content).hexdigest() + try: + resp=requests.get(url) + except requests.exceptions.RequestException as e: + cherrypy.log("Error downloading: %s"%repr(e)) + return None, None + if not resp.status_code==200: + cherrypy.log("Attachment %s failed to download"%filename) + return None, None + hash=do_hash(resp.content).hexdigest() try: fname=fsmanager.hash2fname(hash) dirname=os.path.dirname(fname) @@ -31,6 +37,7 @@ def download_and_cache(url, filename): except OSError as e: cherrypy.log("Error writing "+filename+" to disk: "+repr(e)) return None, None + return None, None def download_uncached(hash): with fsmanager.MetaFile(hash) as metafd: @@ -41,11 +48,12 @@ def download_uncached(hash): for source in data["sources"]: match source["type"]: case "discord": - return download_uncached_discord( + hash, fname=download_uncached_discord( channel=source["channel"], msgid=source["message"], attachmentid=source["attachment"] ) + if hash: return hash, fname case _: # NOTE: maybe log here? return None, None |
