fix(app): handle missing body in wiki article parsing

Add a check for a missing body element when parsing wiki articles and return an error message with a 500 status code if the body is not found. This improves error handling and prevents crashes caused by unexpected HTML structures.
This commit is contained in:
Kumi 2024-08-25 16:56:48 +02:00
parent 88d20e6e6e
commit e2793d4ef6
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -261,6 +261,17 @@ def wiki_article(
soup = BeautifulSoup(article_html, "html.parser")
body = soup.find("body")
if not body:
return (
render_template(
"article.html",
title="Error",
content="An error occurred while fetching the article.",
),
500,
)
body.name = "div"
redirect_message = soup.find("div", class_="redirectMsg")