forked from PrivateCoffee/wikimore
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:
parent
e2793d4ef6
commit
00bd64413d
1 changed files with 3 additions and 8 deletions
|
@ -263,14 +263,9 @@ def wiki_article(
|
|||
body = soup.find("body")
|
||||
|
||||
if not body:
|
||||
return (
|
||||
render_template(
|
||||
"article.html",
|
||||
title="Error",
|
||||
content="An error occurred while fetching the article.",
|
||||
),
|
||||
500,
|
||||
)
|
||||
article_html = f"<div class='mw-body-content parsoid-body mediawiki mw-parser-output'>{article_html}</div>"
|
||||
soup = BeautifulSoup(article_html, "html.parser")
|
||||
body = soup.find("div", class_="mw-body-content")
|
||||
|
||||
body.name = "div"
|
||||
|
||||
|
|
Loading…
Reference in a new issue