Spaces:
Running
Running
Update app/main.py
Browse files- app/main.py +19 -3
app/main.py
CHANGED
|
@@ -1,10 +1,11 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
from contextlib import asynccontextmanager
|
| 3 |
|
| 4 |
-
from fastapi import FastAPI
|
| 5 |
from fastapi.middleware.cors import CORSMiddleware
|
| 6 |
from fastapi.staticfiles import StaticFiles
|
| 7 |
-
from fastapi.responses import FileResponse
|
| 8 |
|
| 9 |
from .database import engine, Base
|
| 10 |
from .routers import auth_router, proxy_config_router, proxy_endpoint_router
|
|
@@ -31,6 +32,18 @@ app.add_middleware(
|
|
| 31 |
allow_headers=["*"],
|
| 32 |
)
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
app.include_router(auth_router.router)
|
| 35 |
app.include_router(proxy_config_router.router)
|
| 36 |
app.include_router(proxy_endpoint_router.router)
|
|
@@ -46,4 +59,7 @@ def serve_ui():
|
|
| 46 |
|
| 47 |
@app.get("/health")
|
| 48 |
def health():
|
| 49 |
-
return {
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
import traceback
|
| 3 |
from contextlib import asynccontextmanager
|
| 4 |
|
| 5 |
+
from fastapi import FastAPI, Request
|
| 6 |
from fastapi.middleware.cors import CORSMiddleware
|
| 7 |
from fastapi.staticfiles import StaticFiles
|
| 8 |
+
from fastapi.responses import FileResponse, JSONResponse
|
| 9 |
|
| 10 |
from .database import engine, Base
|
| 11 |
from .routers import auth_router, proxy_config_router, proxy_endpoint_router
|
|
|
|
| 32 |
allow_headers=["*"],
|
| 33 |
)
|
| 34 |
|
| 35 |
+
# Global exception handler — 500 errors ka actual reason dikhayega
|
| 36 |
+
@app.exception_handler(Exception)
|
| 37 |
+
async def global_exception_handler(request: Request, exc: Exception):
|
| 38 |
+
return JSONResponse(
|
| 39 |
+
status_code=500,
|
| 40 |
+
content={
|
| 41 |
+
"detail": str(exc),
|
| 42 |
+
"type": type(exc).__name__,
|
| 43 |
+
"trace": traceback.format_exc().splitlines()[-5:], # last 5 lines
|
| 44 |
+
},
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
app.include_router(auth_router.router)
|
| 48 |
app.include_router(proxy_config_router.router)
|
| 49 |
app.include_router(proxy_endpoint_router.router)
|
|
|
|
| 59 |
|
| 60 |
@app.get("/health")
|
| 61 |
def health():
|
| 62 |
+
return {
|
| 63 |
+
"status": "ok",
|
| 64 |
+
"db": str(engine.url),
|
| 65 |
+
}
|