unified return structure to use error_field instead of message key to correspond to API specification
This commit is contained in:
parent
a68a768277
commit
5ce866936d
@ -94,7 +94,7 @@ class RequestCode_HTTP_403_FORBIDDEN(RequestStatusCode):
|
|||||||
|
|
||||||
def response(self, message="invalid credentials"):
|
def response(self, message="invalid credentials"):
|
||||||
result = {}
|
result = {}
|
||||||
result["message"] = message
|
result["error_field"] = message
|
||||||
return json.dumps(result)
|
return json.dumps(result)
|
||||||
|
|
||||||
|
|
||||||
@ -110,7 +110,7 @@ class RequestCode_HTTP_404_NOT_FOUND(RequestStatusCode):
|
|||||||
|
|
||||||
def response(self, message="no such record"):
|
def response(self, message="no such record"):
|
||||||
result = {}
|
result = {}
|
||||||
result["message"] = message
|
result["error_field"] = message
|
||||||
return json.dumps(result)
|
return json.dumps(result)
|
||||||
|
|
||||||
|
|
||||||
@ -126,6 +126,6 @@ class RequestCode_HTTP_500_INTERNAL_SERVER_ERROR(RequestStatusCode):
|
|||||||
|
|
||||||
def response(self, message="credential lookup mismatch"):
|
def response(self, message="credential lookup mismatch"):
|
||||||
result = {}
|
result = {}
|
||||||
result["message"] = message
|
result["error_field"] = message
|
||||||
return json.dumps(result)
|
return json.dumps(result)
|
||||||
|
|
||||||
|
|||||||
@ -26,7 +26,7 @@ def GetBerths(options):
|
|||||||
logging.error(ex)
|
logging.error(ex)
|
||||||
print(ex)
|
print(ex)
|
||||||
result = {}
|
result = {}
|
||||||
result["message"] = "call failed"
|
result["error_field"] = "call failed"
|
||||||
return json.dumps(result), 500
|
return json.dumps(result), 500
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
|||||||
@ -35,7 +35,7 @@ def GetHistory(options):
|
|||||||
logging.error(ex)
|
logging.error(ex)
|
||||||
print(ex)
|
print(ex)
|
||||||
result = {}
|
result = {}
|
||||||
result["message"] = "call failed"
|
result["error_field"] = "call failed"
|
||||||
return json.dumps("call failed"), 500
|
return json.dumps("call failed"), 500
|
||||||
|
|
||||||
return json.dumps(data, default=model.obj_dict), 200, {'Content-Type': 'application/json; charset=utf-8'}
|
return json.dumps(data, default=model.obj_dict), 200, {'Content-Type': 'application/json; charset=utf-8'}
|
||||||
|
|||||||
@ -39,18 +39,19 @@ def GetUser(options):
|
|||||||
|
|
||||||
if len(data) > 1:
|
if len(data) > 1:
|
||||||
result = {}
|
result = {}
|
||||||
result["message"] = "credential lookup mismatch"
|
result["error_field"] = "credential lookup mismatch"
|
||||||
return json.dumps(result), 500, {'Content-Type': 'application/json; charset=utf-8'}
|
return json.dumps(result), 500, {'Content-Type': 'application/json; charset=utf-8'}
|
||||||
|
|
||||||
result = {}
|
result = {}
|
||||||
result["message"] = "invalid credentials"
|
result["error_field"] = "invalid credentials"
|
||||||
return json.dumps(result), 403, {'Content-Type': 'application/json; charset=utf-8'}
|
return json.dumps(result), 403, {'Content-Type': 'application/json; charset=utf-8'}
|
||||||
|
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logging.error(ex)
|
logging.error(ex)
|
||||||
print(ex)
|
print(ex)
|
||||||
result = {}
|
result = {}
|
||||||
result["message"] = "call failed: " + str(ex)
|
result["error_field"] = "call failed"
|
||||||
|
result["error_description"] = str(ex)
|
||||||
return json.dumps(result), 500, {'Content-Type': 'application/json; charset=utf-8'}
|
return json.dumps(result), 500, {'Content-Type': 'application/json; charset=utf-8'}
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
|||||||
@ -27,7 +27,7 @@ def GetNotifications(options):
|
|||||||
logging.error(ex)
|
logging.error(ex)
|
||||||
print(ex)
|
print(ex)
|
||||||
result = {}
|
result = {}
|
||||||
result["message"] = "call failed"
|
result["error_field"] = "call failed"
|
||||||
return json.dumps(result), 500, {'Content-Type': 'application/json; charset=utf-8'}
|
return json.dumps(result), 500, {'Content-Type': 'application/json; charset=utf-8'}
|
||||||
|
|
||||||
return json.dumps(data, default=model.obj_dict), 200, {'Content-Type': 'application/json; charset=utf-8'}
|
return json.dumps(data, default=model.obj_dict), 200, {'Content-Type': 'application/json; charset=utf-8'}
|
||||||
|
|||||||
@ -46,7 +46,7 @@ def GetParticipant(options):
|
|||||||
logging.error(ex)
|
logging.error(ex)
|
||||||
print(ex)
|
print(ex)
|
||||||
result = {}
|
result = {}
|
||||||
result["message"] = "call failed"
|
result["error_field"] = "call failed"
|
||||||
return json.dumps("call failed"), 500
|
return json.dumps("call failed"), 500
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
|||||||
@ -21,7 +21,7 @@ def GetPorts(token):
|
|||||||
logging.error(ex)
|
logging.error(ex)
|
||||||
print(ex)
|
print(ex)
|
||||||
result = {}
|
result = {}
|
||||||
result["message"] = "call failed"
|
result["error_field"] = "call failed"
|
||||||
return json.dumps(result), 500
|
return json.dumps(result), 500
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
|||||||
@ -42,7 +42,7 @@ def GetShipcalls(options):
|
|||||||
logging.error(ex)
|
logging.error(ex)
|
||||||
print(ex)
|
print(ex)
|
||||||
result = {}
|
result = {}
|
||||||
result["message"] = "call failed"
|
result["error_field"] = "call failed"
|
||||||
return json.dumps(result), 500, {'Content-Type': 'application/json; charset=utf-8'}
|
return json.dumps(result), 500, {'Content-Type': 'application/json; charset=utf-8'}
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
@ -160,7 +160,7 @@ def PostShipcalls(schemaModel):
|
|||||||
logging.error(ex)
|
logging.error(ex)
|
||||||
print(ex)
|
print(ex)
|
||||||
result = {}
|
result = {}
|
||||||
result["message"] = "call failed"
|
result["error_field"] = "call failed"
|
||||||
return json.dumps(result), 500, {'Content-Type': 'application/json; charset=utf-8'}
|
return json.dumps(result), 500, {'Content-Type': 'application/json; charset=utf-8'}
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
@ -271,7 +271,7 @@ def PutShipcalls(schemaModel):
|
|||||||
logging.error(ex)
|
logging.error(ex)
|
||||||
print(ex)
|
print(ex)
|
||||||
result = {}
|
result = {}
|
||||||
result["message"] = "call failed"
|
result["error_field"] = "call failed"
|
||||||
return json.dumps(result), 500, {'Content-Type': 'application/json; charset=utf-8'}
|
return json.dumps(result), 500, {'Content-Type': 'application/json; charset=utf-8'}
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
|||||||
@ -25,7 +25,7 @@ def GetShips(token):
|
|||||||
logging.error(ex)
|
logging.error(ex)
|
||||||
print(ex)
|
print(ex)
|
||||||
result = {}
|
result = {}
|
||||||
result["message"] = "call failed"
|
result["error_field"] = "call failed"
|
||||||
return json.dumps(result), 500, {'Content-Type': 'application/json; charset=utf-8'}
|
return json.dumps(result), 500, {'Content-Type': 'application/json; charset=utf-8'}
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
@ -91,7 +91,7 @@ def PostShip(schemaModel):
|
|||||||
logging.error(ex)
|
logging.error(ex)
|
||||||
print(ex)
|
print(ex)
|
||||||
result = {}
|
result = {}
|
||||||
result["message"] = "call failed"
|
result["error_field"] = "call failed"
|
||||||
return json.dumps(result), 500, {'Content-Type': 'application/json; charset=utf-8'}
|
return json.dumps(result), 500, {'Content-Type': 'application/json; charset=utf-8'}
|
||||||
|
|
||||||
|
|
||||||
@ -133,7 +133,7 @@ def PutShip(schemaModel):
|
|||||||
logging.error(ex)
|
logging.error(ex)
|
||||||
print(ex)
|
print(ex)
|
||||||
result = {}
|
result = {}
|
||||||
result["message"] = "call failed"
|
result["error_field"] = "call failed"
|
||||||
return json.dumps(result), 500, {'Content-Type': 'application/json; charset=utf-8'}
|
return json.dumps(result), 500, {'Content-Type': 'application/json; charset=utf-8'}
|
||||||
|
|
||||||
|
|
||||||
@ -157,12 +157,12 @@ def DeleteShip(options):
|
|||||||
return json.dumps({"id" : options["id"]}), 200, {'Content-Type': 'application/json; charset=utf-8'}
|
return json.dumps({"id" : options["id"]}), 200, {'Content-Type': 'application/json; charset=utf-8'}
|
||||||
|
|
||||||
result = {}
|
result = {}
|
||||||
result["message"] = "no such record"
|
result["error_field"] = "no such record"
|
||||||
return json.dumps(result), 404, {'Content-Type': 'application/json; charset=utf-8'}
|
return json.dumps(result), 404, {'Content-Type': 'application/json; charset=utf-8'}
|
||||||
|
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logging.error(ex)
|
logging.error(ex)
|
||||||
print(ex)
|
print(ex)
|
||||||
result = {}
|
result = {}
|
||||||
result["message"] = "call failed"
|
result["error_field"] = "call failed"
|
||||||
return json.dumps(result), 500, {'Content-Type': 'application/json; charset=utf-8'}
|
return json.dumps(result), 500, {'Content-Type': 'application/json; charset=utf-8'}
|
||||||
@ -35,7 +35,7 @@ def GetTimes(options):
|
|||||||
logging.error(ex)
|
logging.error(ex)
|
||||||
print(ex)
|
print(ex)
|
||||||
result = {}
|
result = {}
|
||||||
result["message"] = "call failed"
|
result["error_field"] = "call failed"
|
||||||
return json.dumps(result), 500, {'Content-Type': 'application/json; charset=utf-8'}
|
return json.dumps(result), 500, {'Content-Type': 'application/json; charset=utf-8'}
|
||||||
|
|
||||||
return json.dumps(data, default=model.obj_dict), 200, {'Content-Type': 'application/json; charset=utf-8'}
|
return json.dumps(data, default=model.obj_dict), 200, {'Content-Type': 'application/json; charset=utf-8'}
|
||||||
@ -104,7 +104,7 @@ def PostTimes(schemaModel):
|
|||||||
logging.error(ex)
|
logging.error(ex)
|
||||||
print(ex)
|
print(ex)
|
||||||
result = {}
|
result = {}
|
||||||
result["message"] = "call failed"
|
result["error_field"] = "call failed"
|
||||||
return json.dumps(result), 500, {'Content-Type': 'application/json; charset=utf-8'}
|
return json.dumps(result), 500, {'Content-Type': 'application/json; charset=utf-8'}
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
@ -164,7 +164,7 @@ def PutTimes(schemaModel):
|
|||||||
logging.error(ex)
|
logging.error(ex)
|
||||||
print(ex)
|
print(ex)
|
||||||
result = {}
|
result = {}
|
||||||
result["message"] = "call failed"
|
result["error_field"] = "call failed"
|
||||||
return json.dumps(result), 500, {'Content-Type': 'application/json; charset=utf-8'}
|
return json.dumps(result), 500, {'Content-Type': 'application/json; charset=utf-8'}
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
@ -195,14 +195,14 @@ def DeleteTimes(options):
|
|||||||
return json.dumps({"id" : options["id"]}), 200, {'Content-Type': 'application/json; charset=utf-8'}
|
return json.dumps({"id" : options["id"]}), 200, {'Content-Type': 'application/json; charset=utf-8'}
|
||||||
|
|
||||||
result = {}
|
result = {}
|
||||||
result["message"] = "no such record"
|
result["error_field"] = "no such record"
|
||||||
return json.dumps(result), 404, {'Content-Type': 'application/json; charset=utf-8'}
|
return json.dumps(result), 404, {'Content-Type': 'application/json; charset=utf-8'}
|
||||||
|
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logging.error(ex)
|
logging.error(ex)
|
||||||
print(ex)
|
print(ex)
|
||||||
result = {}
|
result = {}
|
||||||
result["message"] = "call failed"
|
result["error_field"] = "call failed"
|
||||||
return json.dumps(result), 500, {'Content-Type': 'application/json; charset=utf-8'}
|
return json.dumps(result), 500, {'Content-Type': 'application/json; charset=utf-8'}
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
|||||||
@ -63,7 +63,7 @@ def PutUser(schemaModel):
|
|||||||
commands.execute(query, param={"password_hash" : password_hash, "id" : schemaModel["id"]})
|
commands.execute(query, param={"password_hash" : password_hash, "id" : schemaModel["id"]})
|
||||||
else:
|
else:
|
||||||
result = {}
|
result = {}
|
||||||
result["message"] = "old password invalid"
|
result["error_field"] = "old password invalid"
|
||||||
return json.dumps(result), 400, {'Content-Type': 'application/json; charset=utf-8'}
|
return json.dumps(result), 400, {'Content-Type': 'application/json; charset=utf-8'}
|
||||||
|
|
||||||
return json.dumps({"id" : schemaModel["id"]}), 200
|
return json.dumps({"id" : schemaModel["id"]}), 200
|
||||||
@ -72,7 +72,7 @@ def PutUser(schemaModel):
|
|||||||
logging.error(ex)
|
logging.error(ex)
|
||||||
print(ex)
|
print(ex)
|
||||||
result = {}
|
result = {}
|
||||||
result["message"] = "call failed"
|
result["error_field"] = "call failed"
|
||||||
return json.dumps(result), 500, {'Content-Type': 'application/json; charset=utf-8'}
|
return json.dumps(result), 500, {'Content-Type': 'application/json; charset=utf-8'}
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
|||||||
@ -25,9 +25,9 @@ def auth_guard(role=None):
|
|||||||
try:
|
try:
|
||||||
user_data = check_jwt()
|
user_data = check_jwt()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return json.dumps({"message" : f'{e}', "status": 401}), 401
|
return json.dumps({"error_field" : f'{e}', "status": 401}), 401
|
||||||
if role and role not in user_data['roles']:
|
if role and role not in user_data['roles']:
|
||||||
return json.dumps({"message": 'Authorization required.', "status" : 403}), 403
|
return json.dumps({"error_field": 'Authorization required.', "status" : 403}), 403
|
||||||
# get on to original route
|
# get on to original route
|
||||||
return route_function(*args, **kwargs)
|
return route_function(*args, **kwargs)
|
||||||
decorated_function.__name__ = route_function.__name__
|
decorated_function.__name__ = route_function.__name__
|
||||||
|
|||||||
@ -77,7 +77,7 @@ def create_werkzeug_error_response(ex:Forbidden, status_code:int=403, create_log
|
|||||||
def create_dynamic_exception_response(ex, status_code:int=400, message:typing.Optional[str]=None, create_log:bool=True):
|
def create_dynamic_exception_response(ex, status_code:int=400, message:typing.Optional[str]=None, create_log:bool=True):
|
||||||
message = repr(ex) if message is None else message
|
message = repr(ex) if message is None else message
|
||||||
json_response = create_default_json_response_format(error_field="Exception", error_description=message)
|
json_response = create_default_json_response_format(error_field="Exception", error_description=message)
|
||||||
json_response["message"] = "call failed"
|
json_response["error_field"] = "call failed"
|
||||||
|
|
||||||
serialized_response = json.dumps(json_response, default=str)
|
serialized_response = json.dumps(json_response, default=str)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user