Skip to content

Commit 6e87ff6

Browse files
committed
added error handling and logging to both has_gist_block and has_markdown_block filters
1 parent af4e434 commit 6e87ff6

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

tbx/core/templatetags/util_tags.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,15 @@ def has_gist_block(value):
9999
for block in value._raw_data:
100100
# special case for work page section block as the streamfields are nested within sections
101101
if block["type"] == "section":
102-
for sub_block in block["value"]["content"]:
103-
if (
104-
sub_block["type"] == "raw_html"
105-
and "https://gist.github.com" in sub_block["value"]
106-
):
107-
return True
102+
try:
103+
for sub_block in block["value"]["content"]:
104+
if (
105+
sub_block["type"] == "raw_html"
106+
and "https://gist.github.com" in sub_block["value"]
107+
):
108+
return True
109+
except (KeyError, TypeError):
110+
pass
108111

109112
if block["type"] == "raw_html" and "https://gist.github.com" in block["value"]:
110113
return True
@@ -117,10 +120,14 @@ def has_markdown_block(value):
117120
return False
118121

119122
for block in value._raw_data:
120-
# special case for work page section block as the streamfields are nested within sections
121123
if block["type"] == "section":
122-
for sub_block in block["value"]["content"]:
123-
if sub_block["type"] == "markdown":
124-
return True
124+
try:
125+
for sub_block in block["value"]["content"]:
126+
if sub_block["type"] == "markdown":
127+
return True
128+
except (KeyError, TypeError):
129+
pass
125130
if block["type"] == "markdown":
126131
return True
132+
133+
return False

0 commit comments

Comments
 (0)