mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
Fix: Resolve JSON download errors in Document.download() (#8084)
### What problem does this PR solve? An exception is thrown only when the json file has only two keys, `code` and `message`. In other cases, response.content is returned normally. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
@ -63,9 +63,14 @@ class Document(Base):
|
|||||||
|
|
||||||
def download(self):
|
def download(self):
|
||||||
res = self.get(f"/datasets/{self.dataset_id}/documents/{self.id}")
|
res = self.get(f"/datasets/{self.dataset_id}/documents/{self.id}")
|
||||||
|
error_keys = set(["code", "message"])
|
||||||
try:
|
try:
|
||||||
res = res.json()
|
response = res.json()
|
||||||
|
actual_keys = set(response.keys())
|
||||||
|
if actual_keys == error_keys:
|
||||||
raise Exception(res.get("message"))
|
raise Exception(res.get("message"))
|
||||||
|
else:
|
||||||
|
return res.content
|
||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
return res.content
|
return res.content
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user