Catch parsing errors in image API

Fixes https://sentry.io/organizations/coreos/issues/664440779/
This commit is contained in:
Joseph Schorr 2019-02-18 13:02:46 -05:00
parent 68300b2644
commit eef4094f56

View file

@ -8,11 +8,18 @@ from endpoints.exception import NotFound
def image_dict(image, with_history=False, with_tags=False):
parsed_command = None
if image.command:
try:
parsed_command = json.loads(image.command)
except (ValueError, TypeError):
parsed_command = {'error': 'Could not parse command'}
image_data = {
'id': image.docker_image_id,
'created': format_date(image.created),
'comment': image.comment,
'command': json.loads(image.command) if image.command else None,
'command': parsed_command,
'size': image.image_size,
'uploading': image.uploading,
'sort_index': len(image.parents),