From 00bd64413d7398a35a847ba9043258482fc9ebb2 Mon Sep 17 00:00:00 2001 From: Kumi Date: Sun, 25 Aug 2024 17:04:07 +0200 Subject: [PATCH] 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. --- src/wikimore/app.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/wikimore/app.py b/src/wikimore/app.py index 3990023..6551941 100644 --- a/src/wikimore/app.py +++ b/src/wikimore/app.py @@ -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"
{article_html}
" + soup = BeautifulSoup(article_html, "html.parser") + body = soup.find("div", class_="mw-body-content") body.name = "div"