server/func: handle download errors
This commit is contained in:
parent
4f497d311a
commit
71a4ce8764
2 changed files with 7 additions and 2 deletions
1
API.md
1
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)
|
||||
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in a new issue