Mr-Help commited on
Commit
7e05d53
ยท
verified ยท
1 Parent(s): 6b6dd1e

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +25 -4
main.py CHANGED
@@ -2,6 +2,7 @@ import os
2
  import requests
3
  import sys
4
  from fastapi import FastAPI
 
5
 
6
  app = FastAPI()
7
 
@@ -67,10 +68,30 @@ def main():
67
 
68
  @app.get("/run")
69
  def run():
70
- """ูŠู†ูุฐ ุงู„ูƒูˆุฏ ุนู†ุฏ ุฃูŠ GET"""
71
- result = main()
72
- return {"ok": True, "data": result}
73
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
75
  @app.get("/ping")
76
  def ping():
 
2
  import requests
3
  import sys
4
  from fastapi import FastAPI
5
+ from fastapi.responses import JSONResponse
6
 
7
  app = FastAPI()
8
 
 
68
 
69
  @app.get("/run")
70
  def run():
71
+ try:
72
+ result = main() # ูŠุทุจุน ู†ูุณ ุฑุณุงุฆู„ ุงู„ู„ูˆุฌ ุจุงู„ุถุจุท
73
+ return {"ok": True, "data": result}
74
+ except requests.HTTPError as e:
75
+ resp = e.response
76
+ # ุงุทุจุน ู…ู„ุฎุต ู„ู„ู‘ูˆุฌ ู…ุน ุงู„ุญูุงุธ ุนู„ู‰ ุทุจุงุนุงุช main ูƒู…ุง ู‡ูŠ
77
+ print(f"HTTPError {resp.status_code} on {resp.url}")
78
+ print(resp.text[:500])
79
+ return JSONResponse(
80
+ status_code=resp.status_code,
81
+ content={
82
+ "ok": False,
83
+ "error": "HTTPError",
84
+ "status": resp.status_code,
85
+ "url": resp.url,
86
+ "body_preview": resp.text[:500],
87
+ },
88
+ )
89
+ except Exception as e:
90
+ print("Unhandled error:", str(e))
91
+ return JSONResponse(
92
+ status_code=500,
93
+ content={"ok": False, "error": "UnhandledError", "detail": str(e)},
94
+ )
95
 
96
  @app.get("/ping")
97
  def ping():