From 07a05f2d9c592588a508fec464c41814b35c2a66 Mon Sep 17 00:00:00 2001 From: David Straub Date: Sat, 7 Oct 2023 17:32:51 +0200 Subject: [PATCH] Catch errors in case of broken links (#432) * Note: do not choke on broken links (#431) * get_%s_from_gramps_id does not raise HandleError --- gramps_webapi/api/html.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gramps_webapi/api/html.py b/gramps_webapi/api/html.py index 6c54c28b..7437a735 100644 --- a/gramps_webapi/api/html.py +++ b/gramps_webapi/api/html.py @@ -25,6 +25,7 @@ import bleach from bleach.css_sanitizer import CSSSanitizer +from gramps.gen.errors import HandleError from gramps.gen.lib import Note, NoteType, StyledText from gramps.plugins.lib.libhtml import Html from gramps.plugins.lib.libhtmlbackend import HtmlBackend, process_spaces @@ -108,12 +109,15 @@ def build_link(prop: str, handle: str, obj_class: str) -> str: gramps_id = handle func = db_handle.method("get_%s_from_gramps_id", obj_class) obj = func(gramps_id) + if not obj: + return "" ref = obj.handle elif prop == "handle": ref = handle func = db_handle.method("get_%s_from_handle", obj_class) - obj = func(ref) - if obj is None: + try: + obj = func(ref) + except HandleError: return "" gramps_id = obj.gramps_id else: