diff --git a/API.md b/API.md index df834154..27d4de71 100644 --- a/API.md +++ b/API.md @@ -169,6 +169,7 @@ List of possible error names: - `InvalidPasswordError` - `InvalidRankError` - `InvalidAvatarError` +- `ProcessingError` (failed to generate thumbnail or download remote file) - `ValidationError` (catch all for odd validation errors) diff --git a/server/szurubooru/func/net.py b/server/szurubooru/func/net.py index 65c01c00..62ac4c37 100644 --- a/server/szurubooru/func/net.py +++ b/server/szurubooru/func/net.py @@ -1,9 +1,13 @@ import urllib.request +from szurubooru import errors def download(url): assert url request = urllib.request.Request(url) request.add_header('Referer', url) - with urllib.request.urlopen(request) as handle: - return handle.read() + try: + with urllib.request.urlopen(request) as handle: + return handle.read() + except Exception as e: + raise errors.ProcessingError('Error downloading %s (%s)' % (url, e))