16 lines
480 B
Python
16 lines
480 B
Python
"""JSON error responses shared by /upload and the site API."""
|
|
import httpx
|
|
from fastapi.responses import JSONResponse
|
|
|
|
|
|
def error(status: int, message: str) -> JSONResponse:
|
|
return JSONResponse({"error": message}, status_code=status)
|
|
|
|
|
|
def zipline_message(r: httpx.Response) -> str:
|
|
try:
|
|
body = r.json()
|
|
return str(body.get("error") or body.get("message") or body)
|
|
except ValueError:
|
|
return r.text[:200] or f"Zipline returned {r.status_code}"
|