fix: sanitize upload_url error messages, handle embed failure, add timeout
Browse files- frontend/src/api.js +1 -1
- server/routes/upload.py +8 -3
frontend/src/api.js
CHANGED
|
@@ -42,7 +42,7 @@ export async function getDocuments() {
|
|
| 42 |
}
|
| 43 |
|
| 44 |
export async function uploadUrl(url, workspaceId = "default") {
|
| 45 |
-
const { data } = await api.post("/upload/url", { url, workspace: workspaceId });
|
| 46 |
return data;
|
| 47 |
}
|
| 48 |
|
|
|
|
| 42 |
}
|
| 43 |
|
| 44 |
export async function uploadUrl(url, workspaceId = "default") {
|
| 45 |
+
const { data } = await api.post("/upload/url", { url, workspace: workspaceId }, { timeout: 60000 });
|
| 46 |
return data;
|
| 47 |
}
|
| 48 |
|
server/routes/upload.py
CHANGED
|
@@ -70,10 +70,15 @@ async def upload_url(request: Request, body: UrlUploadRequest):
|
|
| 70 |
except ValueError as e:
|
| 71 |
raise HTTPException(400, str(e))
|
| 72 |
except Exception as e:
|
| 73 |
-
|
|
|
|
| 74 |
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
build_from_vectorstore(get_vectorstore())
|
| 79 |
request.app.state.retriever = get_retriever()
|
|
|
|
| 70 |
except ValueError as e:
|
| 71 |
raise HTTPException(400, str(e))
|
| 72 |
except Exception as e:
|
| 73 |
+
logger.error("URL fetch error for %s: %s", body.url, e)
|
| 74 |
+
raise HTTPException(502, "Failed to fetch URL. Check that the address is reachable and returns HTML.")
|
| 75 |
|
| 76 |
+
try:
|
| 77 |
+
chunks = chunk_documents(documents)
|
| 78 |
+
embed_and_store(chunks)
|
| 79 |
+
except Exception as e:
|
| 80 |
+
logger.error("Embedding/store failed for URL %s: %s", body.url, e)
|
| 81 |
+
raise HTTPException(503, "Failed to index URL content. Try again later.")
|
| 82 |
|
| 83 |
build_from_vectorstore(get_vectorstore())
|
| 84 |
request.app.state.retriever = get_retriever()
|