Fred808 commited on
Commit
93b4614
·
verified ·
1 Parent(s): 9c63164

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +10 -0
main.py CHANGED
@@ -8,6 +8,7 @@ from app.api.api_v1.api import api_router
8
  from app.db.database import init_db
9
  import logging
10
  import sys
 
11
 
12
  # Configure Windows-specific event loop policy
13
  if platform.system() == 'Windows':
@@ -38,13 +39,21 @@ app.add_middleware(
38
  # Include API router
39
  app.include_router(api_router, prefix=settings.API_V1_STR)
40
 
 
 
41
  @app.exception_handler(HTTPException)
42
  async def http_exception_handler(request, exc):
 
43
  return JSONResponse(
44
  status_code=exc.status_code,
45
  content={"detail": exc.detail}
46
  )
47
 
 
 
 
 
 
48
  @app.get("/")
49
  async def root():
50
  return {"message": "POS Backend API", "version": "1.0.0"}
@@ -64,3 +73,4 @@ if __name__ == "__main__":
64
  logger.info("Starting application with Windows-compatible event loop...")
65
  uvicorn.run("main:app", host="0.0.0.0", port=7860, reload=True, log_level="debug")
66
 
 
 
8
  from app.db.database import init_db
9
  import logging
10
  import sys
11
+ from fastapi.responses import PlainTextResponse
12
 
13
  # Configure Windows-specific event loop policy
14
  if platform.system() == 'Windows':
 
39
  # Include API router
40
  app.include_router(api_router, prefix=settings.API_V1_STR)
41
 
42
+
43
+
44
  @app.exception_handler(HTTPException)
45
  async def http_exception_handler(request, exc):
46
+ logger.error(f"HTTP Exception at {request.url}: {exc.detail}")
47
  return JSONResponse(
48
  status_code=exc.status_code,
49
  content={"detail": exc.detail}
50
  )
51
 
52
+ @app.exception_handler(Exception)
53
+ async def unhandled_exception_handler(request, exc):
54
+ logger.error(f"Unhandled exception at {request.url}: {exc}", exc_info=True)
55
+ return PlainTextResponse("Internal Server Error", status_code=500)
56
+
57
  @app.get("/")
58
  async def root():
59
  return {"message": "POS Backend API", "version": "1.0.0"}
 
73
  logger.info("Starting application with Windows-compatible event loop...")
74
  uvicorn.run("main:app", host="0.0.0.0", port=7860, reload=True, log_level="debug")
75
 
76
+