gzdaniel commited on
Commit
22a53ed
·
1 Parent(s): 357fa9f

Improved error handling for document deletion

Browse files

Added HTTPException for not_found status
Added HTTPException for fail status

lightrag/api/routers/document_routes.py CHANGED
@@ -1438,14 +1438,19 @@ def create_document_routes(
1438
 
1439
  try:
1440
  result = await rag.adelete_by_doc_id(doc_id)
1441
- response_data = {
1442
- "doc_id": result.doc_id,
1443
- "message": result.message,
1444
- "status": result.status,
1445
- }
1446
  if "history_messages" in pipeline_status:
1447
  pipeline_status["history_messages"].append(result.message)
1448
- return DeleteDocByIdResponse(**response_data)
 
 
 
 
 
 
 
 
 
 
1449
 
1450
  except Exception as e:
1451
  error_msg = f"Error deleting document {doc_id}: {str(e)}"
 
1438
 
1439
  try:
1440
  result = await rag.adelete_by_doc_id(doc_id)
 
 
 
 
 
1441
  if "history_messages" in pipeline_status:
1442
  pipeline_status["history_messages"].append(result.message)
1443
+
1444
+ if result.status == "not_found":
1445
+ raise HTTPException(status_code=404, detail=result.message)
1446
+ if result.status == "fail":
1447
+ raise HTTPException(status_code=500, detail=result.message)
1448
+
1449
+ return DeleteDocByIdResponse(
1450
+ doc_id=result.doc_id,
1451
+ message=result.message,
1452
+ status=result.status,
1453
+ )
1454
 
1455
  except Exception as e:
1456
  error_msg = f"Error deleting document {doc_id}: {str(e)}"