File tree Expand file tree Collapse file tree 1 file changed +6
-7
lines changed Expand file tree Collapse file tree 1 file changed +6
-7
lines changed Original file line number Diff line number Diff line change @@ -127,15 +127,15 @@ async def update_todo(id: str, request: UpdateTodoRequest):
127
127
@app .delete ("/todos/{id}" , status_code = 204 )
128
128
async def delete_todo (id : str ):
129
129
try :
130
- # Attempt to delete the item using the partition key (id)
131
- response = table .delete_item (Key = {"id" : id })
132
-
133
- # If no item was deleted (i.e., no such key exists), return a 404 error
134
- if not response .get ("Attributes" ):
130
+ # Attempt to delete the item using only the partition key (`id`)
131
+ response = table .delete_item (Key = {"id" : id }) # Using only `id` to identify the item
132
+
133
+ # Check if the HTTP status code indicates a successful deletion
134
+ if response .get ("ResponseMetadata" , {}).get ("HTTPStatusCode" ) != 200 :
135
+ logging .warning (f"Delete operation failed for id { id } : { response } " )
135
136
raise HTTPException (status_code = 404 , detail = "Todo not found" )
136
137
137
138
logging .debug (f"Deleted item with id: { id } " )
138
- # Return nothing (status code 204) to indicate successful deletion
139
139
return {"detail" : "Todo deleted successfully" }
140
140
141
141
except ClientError as e :
@@ -147,7 +147,6 @@ async def delete_todo(id: str):
147
147
raise HTTPException (status_code = 500 , detail = "Error deleting todo" )
148
148
149
149
150
-
151
150
@app .get ("/health" )
152
151
async def health ():
153
152
try :
You can’t perform that action at this time.
0 commit comments