Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

fix: handle auth errors in SSE generators and download routes (#2564)

LearningCircuit2b824a5d1671
diff --git a/src/local_deep_research/research_library/routes/library_routes.py b/src/local_deep_research/research_library/routes/library_routes.py
index 577a74a10a..84066faccc 100644
--- a/src/local_deep_research/research_library/routes/library_routes.py
+++ b/src/local_deep_research/research_library/routes/library_routes.py
@@ -41,6 +41,7 @@ from ..services.pdf_storage_manager import PDFStorageManager
from ..utils import handle_api_error
from ...utilities.db_utils import get_settings_manager
from ...config.paths import get_library_directory
+from ...web.exceptions import AuthenticationRequiredError
# Create Blueprint
library_bp = Blueprint("library", __name__, url_prefix="/library")
@@ -171,7 +172,6 @@ def get_authenticated_user_password(
AuthenticationRequiredError: If no password is available for the user
"""
from ...database.session_passwords import session_password_store
- from ...web.exceptions import AuthenticationRequiredError
session_id = flask_session_id or session.get("session_id")
@@ -639,6 +639,8 @@ def download_text_single(resource_id):
)
return jsonify({"success": True, "error": None})
+ except AuthenticationRequiredError:
+ raise # Let blueprint error handler return 401
except Exception as e:
return handle_api_error(
f"downloading resource {resource_id} as text", e
@@ -655,14 +657,13 @@ def download_all_text():
def generate():
# Get user password for database operations
- from ...web.exceptions import AuthenticationRequiredError
-
try:
user_password = get_authenticated_user_password(
username, flask_session_id
)
except AuthenticationRequiredError:
logger.warning(f"Authentication expired for user {username}")
+ yield f"data: {json.dumps({'progress': 0, 'current': 0, 'total': 0, 'error': 'Authentication required', 'complete': True})}\n\n"
return
download_service = DownloadService(username, user_password)
@@ -796,13 +797,13 @@ def download_bulk():
def generate():
"""Generate progress updates as Server-Sent Events."""
# Get user password for database operations
- from ...web.exceptions import AuthenticationRequiredError
-
try:
user_password = get_authenticated_user_password(
username, flask_session_id
)
except AuthenticationRequiredError:
+ logger.warning(f"Authentication failed for user {username}")
+ yield f"data: {json.dumps({'progress': 0, 'current': 0, 'total': 0, 'error': 'Authentication required', 'complete': True})}\n\n"
return
download_service = DownloadService(username, user_password)
diff --git a/src/local_deep_research/web/templates/pages/download_manager.html b/src/local_deep_research/web/templates/pages/download_manager.html
index 06dc68f471..ce8ac558ba 100644
--- a/src/local_deep_research/web/templates/pages/download_manager.html
+++ b/src/local_deep_research/web/templates/pages/download_manager.html
@@ -1433,7 +1433,13 @@ async function downloadAllNew() {
const data = JSON.parse(line.slice(6));
updateProgress(data);
- if (data.complete) {
+ if (data.error && data.complete) {
+ currentDownloadController = null;
+ setTimeout(() => {
+ closeProgressModal();
+ alert(data.error);
+ }, 1000);
+ } else if (data.complete) {
currentDownloadController = null;
setTimeout(() => {
closeProgressModal();
@@ -1505,7 +1511,13 @@ async function downloadAllAsText() {
const data = JSON.parse(line.slice(6));
updateTextExtractionProgress(data);
- if (data.complete) {
+ if (data.error && data.complete) {
+ currentDownloadController = null;
+ setTimeout(() => {
+ closeProgressModal();
+ alert(data.error);
+ }, 1000);
+ } else if (data.complete) {
currentDownloadController = null;
setTimeout(() => {
closeProgressModal();