Corin1998 commited on
Commit
1b4de71
·
verified ·
1 Parent(s): 1694978

Update irpr/main.py

Browse files
Files changed (1) hide show
  1. irpr/main.py +11 -0
irpr/main.py CHANGED
@@ -95,3 +95,14 @@ def _extract_section(text: str, head: str):
95
  pat = rf"{head}[::]\s*(.*?)(?:\n[^\n]*[::]|\Z)"
96
  m = re.search(pat, text, re.S)
97
  return (m.group(1).strip() if m else "").strip()
 
 
 
 
 
 
 
 
 
 
 
 
95
  pat = rf"{head}[::]\s*(.*?)(?:\n[^\n]*[::]|\Z)"
96
  m = re.search(pat, text, re.S)
97
  return (m.group(1).strip() if m else "").strip()
98
+ # ===== すべての未捕捉例外を JSON で返す =====
99
+ from fastapi.responses import JSONResponse
100
+ from starlette.requests import Request
101
+
102
+ @app.exception_handler(Exception)
103
+ async def _all_exception_handler(request: Request, exc: Exception):
104
+ import traceback
105
+ traceback.print_exc()
106
+ # 200で返すことでフロントの fetch が素直に本文を読める
107
+ return JSONResponse(status_code=200, content={"ok": False, "error": repr(exc)})
108
+