エラーハンドリング
This commit is contained in:
parent
1f8259f04d
commit
06550e28e3
1 changed files with 18 additions and 6 deletions
24
app.py
24
app.py
|
@ -59,9 +59,15 @@ async def cloudflare(zone_id: str, x_token: Union[str, None] = Header()):
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
res = JSONResponse(result.json())
|
json = result.json()
|
||||||
res.headers["Cache-Control"] = f"public, max-age=60, s-maxage=60"
|
res = JSONResponse(json)
|
||||||
res.headers["CDN-Cache-Control"] = f"max-age=60"
|
if "success" in json and not json["success"]:
|
||||||
|
res.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
|
||||||
|
res.headers["Cache-Control"] = f"public, max-age=0, s-maxage=0"
|
||||||
|
res.headers["CDN-Cache-Control"] = f"max-age=0"
|
||||||
|
else:
|
||||||
|
res.headers["Cache-Control"] = f"public, max-age=60, s-maxage=60"
|
||||||
|
res.headers["CDN-Cache-Control"] = f"max-age=60"
|
||||||
return res
|
return res
|
||||||
|
|
||||||
@app.get("/api/cloudflare2")
|
@app.get("/api/cloudflare2")
|
||||||
|
@ -89,9 +95,15 @@ async def cloudflare2(zone_id: str, x_token: Union[str, None] = Header()):
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
res = JSONResponse(result.json())
|
json = result.json()
|
||||||
res.headers["Cache-Control"] = f"public, max-age=60, s-maxage=60"
|
res = JSONResponse(json)
|
||||||
res.headers["CDN-Cache-Control"] = f"max-age=60"
|
if "success" in json and not json["success"]:
|
||||||
|
res.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
|
||||||
|
res.headers["Cache-Control"] = f"public, max-age=0, s-maxage=0"
|
||||||
|
res.headers["CDN-Cache-Control"] = f"max-age=0"
|
||||||
|
else:
|
||||||
|
res.headers["Cache-Control"] = f"public, max-age=60, s-maxage=60"
|
||||||
|
res.headers["CDN-Cache-Control"] = f"max-age=60"
|
||||||
return res
|
return res
|
||||||
|
|
||||||
@app.get("/")
|
@app.get("/")
|
||||||
|
|
Loading…
Add table
Reference in a new issue