Manage function returns with a generic class
You can get basic-return
from PyPI,
which means it's easily installable with pip
:
python -m pip install basic-return
from basic_return.BasicReturn import BasicReturn
def function(a, b, c=30, d=50):
br = BasicReturn()
if a < 10:
br.status = 10
br.message = "param a is less than 10"
br.payload = {"something": 123456789}
return br
if b > 20:
br.status = -10
br.message = "param b is bigger than 20"
return br
br.status = 20
br.message = "param a is less than 10"
return br
br = function(10, 20, d=40)
if br.status < 0:
print(br.owner_call) # function(a=10, b=20, c=30, d=40); this is how the function was called so we can replicate the error
raise Exception(f"Something bad happens: [{br.status}] - {br.message}")
Refer to the CHANGELOG.md file.