feat: add config error handling on startup
Add error handling for configuration loading at application startup. If the config file is missing or invalid, the app will exit with a clear error message instead of crashing later. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
14
app/main.py
14
app/main.py
@@ -1,7 +1,21 @@
|
||||
import sys
|
||||
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.exceptions import RequestValidationError
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
from config.settings import load_settings
|
||||
|
||||
# 加载配置文件,失败则退出
|
||||
try:
|
||||
settings = load_settings()
|
||||
except FileNotFoundError as e:
|
||||
print(f"配置文件错误: {e}")
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(f"加载配置失败: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
from app.api.v1.location import router as location_router
|
||||
from app.api.v1.box import router as box_router
|
||||
from app.services.location_service import DuplicateLocationError
|
||||
|
||||
Reference in New Issue
Block a user