From e2793d4ef69f894a32b16e769ecd8a72dd7f1724 Mon Sep 17 00:00:00 2001 From: Kumi Date: Sun, 25 Aug 2024 16:56:48 +0200 Subject: [PATCH] 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. --- src/wikimore/app.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/wikimore/app.py b/src/wikimore/app.py index af985f1..3990023 100644 --- a/src/wikimore/app.py +++ b/src/wikimore/app.py @@ -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")