mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-26 01:52:16 +08:00
fix(auth): return HTTP 401 for token-auth failures (#13420)
Follow-up to #12488 #13386 ### What problem does this PR solve? Previously, token authentication failures returned HTTP 200 with an error code in the response body. This PR updates `token_required` to raise `Unauthorized` and relies on the global error handler to return a structured JSON response with HTTP 401 status. The response body structure (`code`, `message`, `data`) remains unchanged to preserve compatibility with the official SDK. Frontend logic has been updated to handle HTTP 401 responses in addition to checking `data.code`. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
@@ -116,7 +116,8 @@ def download_document(auth, dataset_id, document_id, save_path):
|
||||
url = f"{HOST_ADDRESS}{FILE_API_URL}/{document_id}".format(dataset_id=dataset_id)
|
||||
res = requests.get(url=url, auth=auth, stream=True)
|
||||
try:
|
||||
if res.status_code == 200:
|
||||
# available for unauthed downloads
|
||||
if res.status_code in (200, 401):
|
||||
with open(save_path, "wb") as f:
|
||||
for chunk in res.iter_content(chunk_size=8192):
|
||||
f.write(chunk)
|
||||
|
||||
Reference in New Issue
Block a user