refactor(api): Refactor error handling in add() function
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
f7e90567d7
commit
16cf984ddc
3
app.py
3
app.py
@ -201,6 +201,9 @@ def add():
|
|||||||
response_data = {"message": "Fail to add new item"}
|
response_data = {"message": "Fail to add new item"}
|
||||||
return jsonify(response_data), 400
|
return jsonify(response_data), 400
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
if hasattr(e, "message"):
|
||||||
|
error_message = e.message
|
||||||
|
else:
|
||||||
error_message = str(e)
|
error_message = str(e)
|
||||||
response_data = {"message": error_message}
|
response_data = {"message": error_message}
|
||||||
return jsonify(response_data), 400
|
return jsonify(response_data), 400
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user