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`
|
- `InvalidPasswordError`
|
||||||
- `InvalidRankError`
|
- `InvalidRankError`
|
||||||
- `InvalidAvatarError`
|
- `InvalidAvatarError`
|
||||||
|
- `ProcessingError` (failed to generate thumbnail or download remote file)
|
||||||
- `ValidationError` (catch all for odd validation errors)
|
- `ValidationError` (catch all for odd validation errors)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
import urllib.request
|
import urllib.request
|
||||||
|
from szurubooru import errors
|
||||||
|
|
||||||
|
|
||||||
def download(url):
|
def download(url):
|
||||||
assert url
|
assert url
|
||||||
request = urllib.request.Request(url)
|
request = urllib.request.Request(url)
|
||||||
request.add_header('Referer', url)
|
request.add_header('Referer', url)
|
||||||
|
try:
|
||||||
with urllib.request.urlopen(request) as handle:
|
with urllib.request.urlopen(request) as handle:
|
||||||
return handle.read()
|
return handle.read()
|
||||||
|
except Exception as e:
|
||||||
|
raise errors.ProcessingError('Error downloading %s (%s)' % (url, e))
|
||||||
|
|
Loading…
Reference in a new issue