awacke1 commited on
Commit
0c0b92f
ยท
verified ยท
1 Parent(s): 278aa49

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -3
app.py CHANGED
@@ -170,15 +170,18 @@ def update_record(container, updated_record):
170
  except Exception as e:
171
  return False, f"Error: {traceback.format_exc()} ๐Ÿ˜ฑ"
172
 
173
- # ๐Ÿ—‘๏ธ Delete a Cosmos record by id
174
  def delete_record(container, record):
175
  try:
176
  container.delete_item(item=record['id'], partition_key=record['id'])
177
- return True, f"Deleted {record['id']} ๐Ÿ—‘๏ธ"
178
  except exceptions.CosmosHttpResponseError as e:
 
 
 
179
  return False, f"HTTP error: {str(e)} ๐Ÿšจ"
180
  except Exception as e:
181
- return False, f"Error: {traceback.format_exc()} ๐Ÿ˜ฑ"
182
 
183
  # ๐Ÿ’พ Save a new document to Cosmos DB with extra fields
184
  def save_to_cosmos_db(container, query, response1, response2):
 
170
  except Exception as e:
171
  return False, f"Error: {traceback.format_exc()} ๐Ÿ˜ฑ"
172
 
173
+ # ๐Ÿ—‘๏ธ Delete record โ€“ now treats 404 as success
174
  def delete_record(container, record):
175
  try:
176
  container.delete_item(item=record['id'], partition_key=record['id'])
177
+ return True, f"Record {record['id']} successfully deleted. ๐Ÿ—‘๏ธ"
178
  except exceptions.CosmosHttpResponseError as e:
179
+ # If the document is not found, consider it already deleted
180
+ if e.status_code == 404:
181
+ return True, f"Record {record['id']} not found (already deleted). ๐Ÿ—‘๏ธ"
182
  return False, f"HTTP error: {str(e)} ๐Ÿšจ"
183
  except Exception as e:
184
+ return False, f"Unexpected error: {traceback.format_exc()} ๐Ÿ˜ฑ"
185
 
186
  # ๐Ÿ’พ Save a new document to Cosmos DB with extra fields
187
  def save_to_cosmos_db(container, query, response1, response2):