diff --git a/api_service/api_server.py b/api_service/api_server.py index 3cdfc8e..03bff8e 100644 --- a/api_service/api_server.py +++ b/api_service/api_server.py @@ -402,13 +402,21 @@ app = FastAPI(title="Unified API Service", lifespan=lifespan, debug=True) @app.exception_handler(StarletteHTTPException) async def teapot_override(request: Request, exc: StarletteHTTPException): - # Check if this is a request to the openrouterkey endpoint - if request.url.path == "/openrouterkey" or request.url.path.endswith("/openrouterkey"): - # Don't convert 404 errors for the openrouterkey endpoint to 418 - log.warning(f"Exception in openrouterkey endpoint: {exc.status_code} - {exc.detail}") - raise exc + # Check if this is a request to an openrouterkey endpoint (case-insensitive check for 'openrouterkey' part) + path_lower = str(request.url.path).lower() # Ensure path is string and lowercased + is_openrouterkey_related_path = ( + path_lower == "/openrouterkey" or + path_lower == "/api/openrouterkey" or + path_lower == "/discordapi/openrouterkey" + ) - # For all other 404 errors, return a teapot response + if is_openrouterkey_related_path: + # For openrouterkey related paths, log the actual exception and re-raise it. + # This means if it's a 404, it stays a 404. If it's 403, it stays 403, etc. + log.warning(f"Exception for openrouterkey path '{request.url.path}': {exc.status_code} - {exc.detail}") + raise exc # Re-raise the original exception + + # For all other paths that result in a 404: if exc.status_code == 404: log.info(f"Converting 404 to 418 teapot for path: {request.url.path}") html_content = """