Fix mypy issue to catch situation where we might not have a client address
All checks were successful
pip-audit / build (3.11) (pull_request) Successful in 11m22s
Bandit / build (3.11) (push) Successful in 10s
Flake8 / build (3.11) (push) Successful in 8s
Mypy / build (3.11) (push) Successful in 3m30s
Pylint / build (3.11) (push) Successful in 30s

This commit is contained in:
2026-03-14 17:05:49 +01:00
parent 97a4a797b2
commit 5427fc69b0

View File

@ -7,7 +7,8 @@ from typing import Annotated, Optional, Union
import geoip2.database import geoip2.database
from dotenv import load_dotenv from dotenv import load_dotenv
from fastapi import Body, FastAPI, Path, Request, Response, status from fastapi import (Body, FastAPI, HTTPException, Path, Request, Response,
status)
from fastapi.middleware.cors import CORSMiddleware from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import RedirectResponse from fastapi.responses import RedirectResponse
from geoip2.errors import AddressNotFoundError from geoip2.errors import AddressNotFoundError
@ -126,4 +127,6 @@ def root_redirect(req: Request) -> RedirectResponse:
''' '''
Redirect empty request using REMOTE_ADDR Redirect empty request using REMOTE_ADDR
''' '''
if not req.client:
raise HTTPException(status_code=404, detail="Item not found")
return RedirectResponse(url=str(req.url) + str(req.client.host)) return RedirectResponse(url=str(req.url) + str(req.client.host))