From 88a9d98c0a64221fc38cceab9bb8380b392098aa Mon Sep 17 00:00:00 2001 From: Lorenz Padberg Date: Wed, 3 Aug 2022 11:25:19 +0200 Subject: [PATCH] Improve document not found error handling --- server/api/graphene_wagtail.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/server/api/graphene_wagtail.py b/server/api/graphene_wagtail.py index 79df0c83..25eb0122 100644 --- a/server/api/graphene_wagtail.py +++ b/server/api/graphene_wagtail.py @@ -88,18 +88,21 @@ def augment_fields(raw_data): data['value'] = augment_fields(item_data) if _type == 'cms_document_block': - _value = data['value'] - document = CustomDocument.objects.get(id=_value) - value = { - 'value': _value, - 'id': document.id, - 'file_name': document.filename, - 'file_extension': document.file_extension, - 'url': document.url, - 'title': document.title, - 'display_text': document.display_text - } - data['value'] = value + try: + _value = data['value'] + document = CustomDocument.objects.get(id=_value) + value = { + 'value': _value, + 'id': document.id, + 'file_name': document.filename, + 'file_extension': document.file_extension, + 'url': document.url, + 'title': document.title, + 'display_text': document.display_text + } + data['value'] = value + except CustomDocument.DoesNotExist: + logger.error('CustomDocument {} does not exist'.format(_value)) return raw_data