19 lines
634 B
Python
19 lines
634 B
Python
from typing import Any, Optional, Tuple, TypedDict
|
|
|
|
|
|
class ErrorReturn(TypedDict):
|
|
status: int
|
|
message: Optional[str]
|
|
details: Optional[dict[str, Any]]
|
|
|
|
|
|
def generate_error(status: int, message: Optional[str]=None, additional_data: Optional[dict[str, Any]]=None) -> Tuple[ErrorReturn, int]:
|
|
obj: ErrorReturn = { "status": status }
|
|
if message is not None:
|
|
obj |= { "message": message }
|
|
if additional_data is not None:
|
|
obj |= { "details": additional_data }
|
|
return obj, status
|
|
|
|
def convert_to_bool(val: str) -> bool:
|
|
return bool(val) if str(val).lower() not in ("null", "none") else False
|