2023-08-01 20:19:18 +02:00
|
|
|
import json
|
|
|
|
import starlette
|
|
|
|
|
2023-08-12 17:49:31 +02:00
|
|
|
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."""
|
|
|
|
|
2023-08-01 20:19:18 +02:00
|
|
|
info = {'error': {
|
|
|
|
'code': code,
|
|
|
|
'message': message,
|
|
|
|
'tip': tip,
|
2023-10-05 14:17:53 +02:00
|
|
|
'powered_by': 'nova-api'
|
2023-08-01 20:19:18 +02:00
|
|
|
}}
|
|
|
|
|
|
|
|
return starlette.responses.Response(status_code=code, content=json.dumps(info))
|
2023-08-06 00:43:36 +02:00
|
|
|
|
2023-08-06 21:42:07 +02:00
|
|
|
async def yield_error(code: int, message: str, tip: str) -> str:
|
2023-08-12 17:49:31 +02:00
|
|
|
"""Returns a dumped JSON response with the given error code, message and tip."""
|
|
|
|
|
2023-08-06 00:43:36 +02:00
|
|
|
return json.dumps({
|
|
|
|
'code': code,
|
|
|
|
'message': message,
|
2023-10-05 14:17:53 +02:00
|
|
|
'tip': tip,
|
|
|
|
'powered_by': 'nova-api'
|
2023-08-06 00:43:36 +02:00
|
|
|
})
|