diff options
| author | rr- | 2016-09-25 14:52:47 +0200 |
|---|---|---|
| committer | rr- | 2016-09-25 14:52:47 +0200 |
| commit | 71a4ce876401fa239671ae32dbb53c05fb4acdbc (patch) | |
| tree | 08707e976b1bb3d943cdd0da0902027d251eb1f6 | |
| parent | 4f497d311a5b2044a36e5beb6ac6da1e4a0ba8e2 (diff) | |
server/func: handle download errors
| -rw-r--r-- | API.md | 1 | ||||
| -rw-r--r-- | server/szurubooru/func/net.py | 8 |
2 files changed, 7 insertions, 2 deletions
@@ -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 65c01c0..62ac4c3 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)) |