musicdlp/backend/response.py

27 lines
520 B
Python
Raw Normal View History

2024-05-02 16:18:27 +03:00
import json
import traceback
2024-05-02 16:18:27 +03:00
OK = '{"ok":true}'
def ok_playlist(items: list[str]) -> str:
2024-05-02 16:18:27 +03:00
return json.dumps({
"ok": True,
"data": items,
2024-05-02 16:18:27 +03:00
})
def ok_downloaded(ret: int) -> str:
2024-05-02 16:18:27 +03:00
return json.dumps({
"type": "downloaded",
"data": ret,
2024-05-02 16:18:27 +03:00
})
def error(ex: Exception) -> str:
traceback.print_tb(ex.__traceback__)
2024-05-02 16:18:27 +03:00
return json.dumps({
"ok": False,
"error": {
"type": ex.__class__.__qualname__,
"message": str(ex),
}
2024-05-02 16:18:27 +03:00
})