Skip to content

Commit 07a05f2

Browse files
author
David Straub
authored
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
1 parent 2a99b0c commit 07a05f2

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

gramps_webapi/api/html.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import bleach
2727
from bleach.css_sanitizer import CSSSanitizer
28+
from gramps.gen.errors import HandleError
2829
from gramps.gen.lib import Note, NoteType, StyledText
2930
from gramps.plugins.lib.libhtml import Html
3031
from gramps.plugins.lib.libhtmlbackend import HtmlBackend, process_spaces
@@ -108,12 +109,15 @@ def build_link(prop: str, handle: str, obj_class: str) -> str:
108109
gramps_id = handle
109110
func = db_handle.method("get_%s_from_gramps_id", obj_class)
110111
obj = func(gramps_id)
112+
if not obj:
113+
return ""
111114
ref = obj.handle
112115
elif prop == "handle":
113116
ref = handle
114117
func = db_handle.method("get_%s_from_handle", obj_class)
115-
obj = func(ref)
116-
if obj is None:
118+
try:
119+
obj = func(ref)
120+
except HandleError:
117121
return ""
118122
gramps_id = obj.gramps_id
119123
else:

0 commit comments

Comments
 (0)