Small api logic changes, small order changes

This commit is contained in:
2022-09-29 00:32:18 +03:00
parent 19b246ec06
commit 6f3beeec09
8 changed files with 80 additions and 20 deletions

View File

@@ -44,26 +44,28 @@ API_ERROR_VALIDATION = {
def make_error_object(ex: Exception):
data = {
"status": "error"
}
try:
if type(ex.args[0]) != tuple:
raise Exception(API_ERROR_INTERNAL_ERROR)
raise ex
data = {
"error": {
"code": ex.args[0][0],
"message": ex.args[0][1]
}
data["error"] = {
"code": ex.args[0][0],
"message": ex.args[0][1]
}
if len(ex.args) >= 2:
data["error"]["related"] = ex.args[1]
return data
except Exception:
except BaseException as err:
traceback.print_exc()
return {
"error": {
"code": API_ERROR_INTERNAL_ERROR[0],
"message": API_ERROR_INTERNAL_ERROR[1]
}
data["error"] = {
"code": API_ERROR_INTERNAL_ERROR[0],
"message": API_ERROR_INTERNAL_ERROR[1],
"related": f"Exception {type(err)}: {str(err)}"
}
return data