From 7e2638d91dc55698e2818d65e09c777e1e04b2e8 Mon Sep 17 00:00:00 2001 From: vvzvlad Date: Sat, 1 Feb 2025 20:57:57 +0300 Subject: [PATCH] Simplify post HTML rendering and error handling in API server --- api_server.py | 46 ++++------------------------------------------ 1 file changed, 4 insertions(+), 42 deletions(-) diff --git a/api_server.py b/api_server.py index 788c44f..2045277 100644 --- a/api_server.py +++ b/api_server.py @@ -22,49 +22,11 @@ async def shutdown(): async def get_post_html(channel: str, post_id: int): try: post = await client.get_post(channel, post_id) - if post.get("error"): - raise HTTPException( - status_code=404, - detail=post["details"] - ) - return f""" - - - Post {post_id} - - - - {post['text']} - - - """ + if "error" in post: + raise HTTPException(status_code=404, detail=post["details"]) + return post["html"] except Exception as e: - logger.error(f"HTML endpoint error: {str(e)}") + logger.error(f"Error in get_post_html: {str(e)}") raise HTTPException(status_code=500, detail=str(e)) @app.get("/json/{channel}/{post_id}")