Skip to content

Commit

Permalink
Catch errors in case of broken links (#432)
Browse files Browse the repository at this point in the history
* Note: do not choke on broken links (#431)

* get_%s_from_gramps_id does not raise HandleError
  • Loading branch information
DavidMStraub authored Oct 7, 2023
1 parent 2a99b0c commit 07a05f2
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions gramps_webapi/api/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 07a05f2

Please sign in to comment.