Improve API Documentation, Standardize Error Handling, and Enhance Comments (#5990)

### What problem does this PR solve?  
- The API documentation lacks detailed error code explanations. Added
error code tables to `python_api_reference.md` and
`http_api_reference.md` to clarify possible error codes and their
meanings.
- Error handling in the codebase is inconsistent. Standardized error
handling logic in `sdk/python/ragflow_sdk/modules/chunk.py`.
- Improved API comments by adding standardized docstrings to enhance
code readability and maintainability.

### Type of change  
- [x] Documentation Update  
- [x] Refactoring
This commit is contained in:
Xinghan Pan
2025-03-13 19:06:50 +08:00
committed by GitHub
parent 940072592f
commit 47926f7d21
8 changed files with 591 additions and 24 deletions

View File

@ -16,6 +16,12 @@
from .base import Base
class ChunkUpdateError(Exception):
def __init__(self, code=None, message=None, details=None):
self.code = code
self.message = message
self.details = details
super().__init__(message)
class Chunk(Base):
def __init__(self, rag, res_dict):
@ -38,4 +44,8 @@ class Chunk(Base):
res = self.put(f"/datasets/{self.dataset_id}/documents/{self.document_id}/chunks/{self.id}", update_message)
res = res.json()
if res.get("code") != 0:
raise Exception(res["message"])
raise ChunkUpdateError(
code=res.get("code"),
message=res.get("message"),
details=res.get("details")
)