Implemented 400 response code on error
This commit is contained in:
@@ -21,33 +21,35 @@ def process_xml(request: request, type: str) -> str:
|
|||||||
:rtype: str
|
:rtype: str
|
||||||
"""
|
"""
|
||||||
start = time.time_ns()
|
start = time.time_ns()
|
||||||
|
code = 200
|
||||||
response = dict()
|
response_json = dict()
|
||||||
try:
|
try:
|
||||||
request_data = json.loads(request.get_data(as_text=True))
|
request_data = json.loads(request.get_data(as_text=True))
|
||||||
data = request_data['data']
|
data = request_data['data']
|
||||||
process = request_data['process']
|
process = request_data['process']
|
||||||
if (type == "xsd"):
|
if (type == "xsd"):
|
||||||
response['result'] = Parser.xsd(data, process)
|
response_json['result'] = Parser.xsd(data, process)
|
||||||
elif (type == "xslt"):
|
elif (type == "xslt"):
|
||||||
response['result'] = Parser.xslt(data, process)
|
response_json['result'] = Parser.xslt(data, process)
|
||||||
elif (type == "xpath"):
|
elif (type == "xpath"):
|
||||||
response['result'] = Parser.xpath(data, process)
|
response_json['result'] = Parser.xpath(data, process)
|
||||||
else:
|
else:
|
||||||
raise ValueError("Valid operation types are: xsd, xslt, xpath")
|
raise ValueError("Valid operation types are: xsd, xslt, xpath")
|
||||||
|
|
||||||
response['status'] = "OK"
|
response_json['status'] = "OK"
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
response['result'] = "Missing key: " + str(e)
|
response_json['result'] = "Missing key: " + str(e)
|
||||||
response['status'] = "ERR"
|
response_json['status'] = "ERR"
|
||||||
|
code = 400
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
response['result'] = str(e)
|
response_json['result'] = str(e)
|
||||||
response['status'] = "ERR"
|
response_json['status'] = "ERR"
|
||||||
|
code = 400
|
||||||
finally:
|
finally:
|
||||||
exec_time = (time.time_ns() - start) / 10**6
|
exec_time = (time.time_ns() - start) / 10**6
|
||||||
response['time'] = f"{exec_time:.03f}"
|
response_json['time'] = f"{exec_time:.03f}"
|
||||||
response['processor'] = "libxml2 over lxml"
|
response_json['processor'] = "libxml2 over lxml"
|
||||||
return json.dumps(response)
|
return json.dumps(response_json), code
|
||||||
|
|
||||||
|
|
||||||
@app.route("/xpathpost", methods=["POST"])
|
@app.route("/xpathpost", methods=["POST"])
|
||||||
|
|||||||
Reference in New Issue
Block a user