From c3918c3d35afff2e8f3c56808bd322b8bde87fb1 Mon Sep 17 00:00:00 2001 From: Redume Date: Mon, 30 Sep 2024 16:55:16 +0300 Subject: [PATCH] change statuscode condition --- src/routes/wallpaper.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/routes/wallpaper.py b/src/routes/wallpaper.py index 431bf15..21aa73b 100644 --- a/src/routes/wallpaper.py +++ b/src/routes/wallpaper.py @@ -4,6 +4,7 @@ from fastapi.templating import Jinja2Templates import requests from datetime import datetime +from http import HTTPStatus router = APIRouter() @@ -15,7 +16,9 @@ async def today_wallpaper(request: Request): date = datetime.today().strftime('%Y-%m-%d') res = requests.get(f'https://api.starlio.space/last') - if res.status_code != 200: + if not HTTPStatus(res.status_code).is_redirection or \ + not HTTPStatus(res.status_code).is_success: + return FileResponse('./src/web/html/error/404.html') return RedirectResponse(f'/wallpaper/{date}') @@ -25,7 +28,8 @@ async def today_wallpaper(request: Request): async def wallpaper(request: Request, day): res = requests.get(f'https://api.starlio.space/wallpaper/{day}') - if res.status_code != 200: + if not HTTPStatus(res.status_code).is_redirection or \ + not HTTPStatus(res.status_code).is_success: return FileResponse('./src/web/html/error/404.html') return template.TemplateResponse(