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.

refactor: consolidate delete_manager.js fetch utilities (#2935)

LearningCircuitaec67faa3ebc
diff --git a/src/local_deep_research/web/static/js/deletion/delete_manager.js b/src/local_deep_research/web/static/js/deletion/delete_manager.js
index 23347becf0..275b5ce8f1 100644
--- a/src/local_deep_research/web/static/js/deletion/delete_manager.js
+++ b/src/local_deep_research/web/static/js/deletion/delete_manager.js
@@ -29,77 +29,32 @@ const DELETE_API = {
BULK_PREVIEW: '/library/api/documents/preview'
};
-/**
- * Get CSRF token from meta tag
- */
-function getCsrfToken() {
- return window.api ? window.api.getCsrfToken() : '';
-}
-
/**
* Make a DELETE request to the API
*/
async function deleteRequest(url, body = null) {
- const options = {
- method: 'DELETE',
- headers: {
- 'Content-Type': 'application/json',
- 'X-CSRFToken': getCsrfToken()
- }
- };
-
+ const options = { method: 'DELETE' };
if (body) {
options.body = JSON.stringify(body);
}
-
- const response = await fetch(url, options);
- const data = await response.json();
-
- if (!response.ok) {
- throw new Error(data.error || `Request failed with status ${response.status}`);
- }
-
- return data;
+ return window.api.fetchWithErrorHandling(url, options);
}
/**
* Make a GET request to the API
*/
async function getRequest(url) {
- const response = await fetch(url, {
- method: 'GET',
- headers: {
- 'X-CSRFToken': getCsrfToken()
- }
- });
- const data = await response.json();
-
- if (!response.ok) {
- throw new Error(data.error || `Request failed with status ${response.status}`);
- }
-
- return data;
+ return window.api.fetchWithErrorHandling(url, { method: 'GET' });
}
/**
* Make a POST request to the API
*/
async function postRequest(url, body) {
- const response = await fetch(url, {
+ return window.api.fetchWithErrorHandling(url, {
method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- 'X-CSRFToken': getCsrfToken()
- },
body: JSON.stringify(body)
});
- const data = await response.json();
-
- if (!response.ok) {
- throw new Error(data.error || `Request failed with status ${response.status}`);
- }
-
- return data;
}
/**
diff --git a/src/local_deep_research/web/static/js/services/api.js b/src/local_deep_research/web/static/js/services/api.js
index 7339e620f4..30c39c2ebc 100644
--- a/src/local_deep_research/web/static/js/services/api.js
+++ b/src/local_deep_research/web/static/js/services/api.js
@@ -56,7 +56,7 @@ async function fetchWithErrorHandling(url, options = {}) {
// Handle non-200 responses
if (!response.ok) {
const errorData = await response.json().catch(() => ({}));
- throw new Error(errorData.message || `API Error: ${response.status} ${response.statusText}`);
+ throw new Error(errorData.message || errorData.error || `API Error: ${response.status} ${response.statusText}`);
}
// Parse the response
@@ -288,6 +288,7 @@ if (typeof window !== 'undefined') {
saveLlmConfig,
postJSON,
getApiUrl,
- getCsrfToken
+ getCsrfToken,
+ fetchWithErrorHandling
};
}