fix: handle missing body in wiki article response

Updated the error handling to address cases where the body is missing in the wiki article response. Instead of returning an error page, the code now constructs a default HTML structure and uses BeautifulSoup to parse it, ensuring the body content can still be located and processed. This improves robustness and user experience when dealing with incomplete or malformed article data.

Fixes #24.
This commit is contained in:
Kumi 2024-08-25 17:04:07 +02:00
parent e2793d4ef6
commit 00bd64413d
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -263,14 +263,9 @@ def wiki_article(
body = soup.find("body") body = soup.find("body")
if not body: if not body:
return ( article_html = f"<div class='mw-body-content parsoid-body mediawiki mw-parser-output'>{article_html}</div>"
render_template( soup = BeautifulSoup(article_html, "html.parser")
"article.html", body = soup.find("div", class_="mw-body-content")
title="Error",
content="An error occurred while fetching the article.",
),
500,
)
body.name = "div" body.name = "div"