Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from fastapi import FastAPI, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse
import traceback
from fastapi import Request
from .auth.routes import router as auth_router
from .example_protected_routes import router as protected_router
import os
Expand Down Expand Up @@ -28,11 +30,23 @@
app.include_router(protected_router)

# Global exception handler


@app.exception_handler(Exception)
async def global_exception_handler(request, exc):
async def global_exception_handler(request: Request, exc: Exception):
# Log full traceback (could also write to a file or logging service)
print(f"Unhandled Exception: {exc}")
traceback.print_exc()

# You can add more detailed errors in dev mode
is_dev = os.environ.get("ENV", "dev") == "dev"
return JSONResponse(
status_code=500,
content={"detail": "Internal server error"}
content={
"detail": "Internal server error",
"error": str(exc) if is_dev else None,
"path": request.url.path
},
)

# Health check endpoint
Expand All @@ -51,4 +65,4 @@ async def root():
"auth": "/auth",
"protected": "/protected"
}
}
}