sixfingerdev commited on
Commit
1a66205
·
verified ·
1 Parent(s): f6a681e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -14
app.py CHANGED
@@ -312,31 +312,43 @@ async def get_stats(authorization: str = Header(None)):
312
  "requests_last_minute": sum(len(v) for v in REQUEST_COUNTS.values())
313
  }
314
 
 
 
 
 
 
315
  # ============================================
316
  # ERROR HANDLERS
317
  # ============================================
318
 
319
  @app.exception_handler(HTTPException)
320
  async def http_exception_handler(request, exc):
321
- return {
322
- "error": {
323
- "message": exc.detail,
324
- "type": "api_error",
325
- "code": exc.status_code
 
 
 
326
  }
327
- }
328
 
329
  @app.exception_handler(Exception)
330
  async def general_exception_handler(request, exc):
331
- return {
332
- "error": {
333
- "message": str(exc),
334
- "type": "internal_error",
335
- "code": 500
 
 
 
 
 
 
336
  }
337
- }
338
-
339
- # ============================================
340
  # STARTUP
341
  # ============================================
342
 
 
312
  "requests_last_minute": sum(len(v) for v in REQUEST_COUNTS.values())
313
  }
314
 
315
+ # ============================================
316
+ # ERROR HANDLERS
317
+ # ============================================
318
+ from starlette.responses import JSONResponse # En üste ekle, zaten FastAPI'den geliyor ama emin ol
319
+
320
  # ============================================
321
  # ERROR HANDLERS
322
  # ============================================
323
 
324
  @app.exception_handler(HTTPException)
325
  async def http_exception_handler(request, exc):
326
+ return JSONResponse(
327
+ status_code=exc.status_code,
328
+ content={
329
+ "error": {
330
+ "message": exc.detail,
331
+ "type": "api_error",
332
+ "code": exc.status_code
333
+ }
334
  }
335
+ )
336
 
337
  @app.exception_handler(Exception)
338
  async def general_exception_handler(request, exc):
339
+ # Logla hatayı (production'da önemli)
340
+ print(f"Unhandled exception: {exc}")
341
+
342
+ return JSONResponse(
343
+ status_code=500,
344
+ content={
345
+ "error": {
346
+ "message": "Internal server error",
347
+ "type": "internal_error",
348
+ "code": 500
349
+ }
350
  }
351
+ )# ============================================
 
 
352
  # STARTUP
353
  # ============================================
354