mirror of
https://github.com/NovaOSS/nova-api.git
synced 2024-11-26 00:23:57 +01:00
25 lines
707 B
Python
25 lines
707 B
Python
import json
|
|
import starlette
|
|
|
|
async def error(code: int, message: str, tip: str) -> starlette.responses.Response:
|
|
"""Returns a starlette response JSON with the given error code, message and tip."""
|
|
|
|
info = {'error': {
|
|
'code': code,
|
|
'message': message,
|
|
'tip': tip,
|
|
'powered_by': 'nova-api'
|
|
}}
|
|
|
|
return starlette.responses.Response(status_code=code, content=json.dumps(info))
|
|
|
|
async def yield_error(code: int, message: str, tip: str) -> str:
|
|
"""Returns a dumped JSON response with the given error code, message and tip."""
|
|
|
|
return json.dumps({
|
|
'code': code,
|
|
'message': message,
|
|
'tip': tip,
|
|
'powered_by': 'nova-api'
|
|
})
|