Update main.py
Browse files
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 |
-
|
| 71 |
-
|
| 72 |
-
|
| 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():
|