benroshan commited on
Commit
4f14900
·
1 Parent(s): ee2b23c

fix: sanitize upload_url error messages, handle embed failure, add timeout

Browse files
Files changed (2) hide show
  1. frontend/src/api.js +1 -1
  2. 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
- raise HTTPException(502, f"Failed to fetch URL: {e}")
 
74
 
75
- chunks = chunk_documents(documents)
76
- embed_and_store(chunks)
 
 
 
 
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()