in flask i return simple json string like this : in case of error:
the Exception coming from this :
try:
self.data.add('data', self.request.data)
except Exception as err:
print(traceback.format_exc())
return _build_response_json()
the _build_response_json() function return string json as shown below :
getting this exception/Traceback:
Unable to display children:Error resolving variables Traceback (most recent call last):
File "C:\app\base.py", line 73, in get_name
self.data.add('data', self.request.data)
AttributeError: 'ObjRequest' object has no attribute 'data'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.2\plugins\python-ce\helpers\pydev\_pydevd_bundle\pydevd_resolver.py", line 213, in resolve
return dict[key]
KeyError: 'Exception'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.2\plugins\python-ce\helpers\pydev\_pydevd_bundle\pydevd_comm.py", line 1195, in do_it
_typeName, val_dict = pydevd_vars.resolve_compound_variable_fields(self.thread_id, self.frame_id, self.scope, self.attributes)
File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.2\plugins\python-ce\helpers\pydev\_pydevd_bundle\pydevd_vars.py", line 281, in resolve_compound_variable_fields
var = getVariable(thread_id, frame_id, scope, attrs)
File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.2\plugins\python-ce\helpers\pydev\_pydevd_bundle\pydevd_vars.py", line 239, in getVariable
var = resolver.resolve(var, k)
File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.2\plugins\python-ce\helpers\pydev\_pydevd_bundle\pydevd_resolver.py", line 215, in resolve
return getattr(dict, key)
AttributeError: 'dict' object has no attribute 'Exception'
The json :
def _build_response_json()
retur_json = {
"status": "error",
"title": "error",
"message": "this is error massage from server",
"type": "error",
"status": 500,
"id": "xxxxxi"
}
json_str = json.dumps(retur_json)
return json_str
but in the client side when error
i keep getting :
res.status = 500
error = INTERNAL SERVER ERROR
options = error
$.ajax({
type: "POST",
url: "/execute",
data: data,
success: function (res) {
....
},
error: function (res, options, error) {
console.log(res.status);
console.log(error);
console.log(options);
}
});
what im doing wrong here ?