Skip to content

Commit

Permalink
Fix: server returns a response with 404 code
Browse files Browse the repository at this point in the history
  • Loading branch information
Marishka17 committed Nov 26, 2020
1 parent d2e186a commit ddf2268
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
24 changes: 10 additions & 14 deletions cvat/apps/engine/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
Mpeg4CompressedChunkWriter, ZipChunkWriter, ZipCompressedChunkWriter)
from cvat.apps.engine.models import DataChoice, StorageChoice
from cvat.apps.engine.prepare import PrepareInfo
from .log import slogger

class CacheInteraction:
def __init__(self):
Expand Down Expand Up @@ -47,19 +46,16 @@ def prepare_chunk_buff(self, db_data, quality, chunk_number):
StorageChoice.LOCAL: db_data.get_upload_dirname(),
StorageChoice.SHARE: settings.SHARE_ROOT
}[db_data.storage]
try:
if os.path.exists(db_data.get_meta_path()):
source_path = os.path.join(upload_dir, db_data.video.path)
meta = PrepareInfo(source_path=source_path, meta_path=db_data.get_meta_path())
for frame in meta.decode_needed_frames(chunk_number, db_data):
images.append(frame)
writer.save_as_chunk([(image, source_path, None) for image in images], buff)
else:
with open(db_data.get_dummy_chunk_path(chunk_number), 'r') as dummy_file:
images = [os.path.join(upload_dir, line.strip()) for line in dummy_file]
writer.save_as_chunk([(image, image, None) for image in images], buff)
except FileNotFoundError as ex:
slogger.glob.exception(f"{ex.strerror} {ex.filename}")
if os.path.exists(db_data.get_meta_path()):
source_path = os.path.join(upload_dir, db_data.video.path)
meta = PrepareInfo(source_path=source_path, meta_path=db_data.get_meta_path())
for frame in meta.decode_needed_frames(chunk_number, db_data):
images.append(frame)
writer.save_as_chunk([(image, source_path, None) for image in images], buff)
else:
with open(db_data.get_dummy_chunk_path(chunk_number), 'r') as dummy_file:
images = [os.path.join(upload_dir, line.strip()) for line in dummy_file]
writer.save_as_chunk([(image, image, None) for image in images], buff)

buff.seek(0)
return buff, mime_type
Expand Down
4 changes: 4 additions & 0 deletions cvat/apps/engine/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,10 @@ def data(self, request, pk):
return Response(data='unknown data type {}.'.format(data_type), status=status.HTTP_400_BAD_REQUEST)
except APIException as e:
return Response(data=e.default_detail, status=e.status_code)
except FileNotFoundError as ex:
msg = f"{ex.strerror} {ex.filename}"
slogger.task[pk].error(msg, exc_info=True)
return Response(data=msg, status=status.HTTP_404_NOT_FOUND)
except Exception as e:
msg = 'cannot get requested data type: {}, number: {}, quality: {}'.format(data_type, data_id, data_quality)
slogger.task[pk].error(msg, exc_info=True)
Expand Down

0 comments on commit ddf2268

Please sign in to comment.