diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2022-03-04 21:04:23 +0100 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2022-03-04 21:04:23 +0100 |
commit | 1b2f2b1a7f12cef801922eb5561fa402a9954d32 (patch) | |
tree | 1860f8bb11b63c3253266eb57de28d747434273c /fbin | |
parent | 466ebbf11f958279f20bca9aacd2a2deeaaab2bf (diff) |
file_storage.s3: Return None on NoSuchKey errors
This will cause the file handler to return 404 instead of 500.
Diffstat (limited to 'fbin')
-rw-r--r-- | fbin/file_storage/s3.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/fbin/file_storage/s3.py b/fbin/file_storage/s3.py index b372dd7..25b204c 100644 --- a/fbin/file_storage/s3.py +++ b/fbin/file_storage/s3.py @@ -62,7 +62,12 @@ class Storage(BaseStorage): kwargs = {} if 'Range' in request.headers: kwargs['Range'] = request.headers['Range'] - data = obj.get(**kwargs) + try: + data = obj.get(**kwargs) + except botocore.exceptions.ClientError as e: + if e.response['Error']['Code'] == 'NoSuchKey': + return + raise rv = send_file(data['Body'], attachment_filename=f.filename) rv.headers['Content-Length'] = data['ContentLength'] rv.headers['Accept-Ranges'] = data['AcceptRanges'] |