fix(api): Add error handling for item not found
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Ching 2024-03-04 21:04:59 +08:00
parent 219dd5deee
commit 2e646054ff

3
app.py
View File

@ -203,6 +203,9 @@ def add():
spider = BarcodeSpider(x_rapidapi_key=X_RapidAPI_Key) spider = BarcodeSpider(x_rapidapi_key=X_RapidAPI_Key)
good = spider.get_good(barcode) good = spider.get_good(barcode)
if not good:
response_data = {"message": "Item not found"}
return jsonify(response_data), 400
try: try:
if add_product(good, location): if add_product(good, location):
response_data = {"message": "New item added successfully"} response_data = {"message": "New item added successfully"}