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:
parent
88d20e6e6e
commit
e2793d4ef6
1 changed files with 11 additions and 0 deletions
|
@ -261,6 +261,17 @@ def wiki_article(
|
||||||
soup = BeautifulSoup(article_html, "html.parser")
|
soup = BeautifulSoup(article_html, "html.parser")
|
||||||
|
|
||||||
body = soup.find("body")
|
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"
|
body.name = "div"
|
||||||
|
|
||||||
redirect_message = soup.find("div", class_="redirectMsg")
|
redirect_message = soup.find("div", class_="redirectMsg")
|
||||||
|
|
Loading…
Reference in a new issue