🔧 fix: Error handling in Firebase and Local file deletion (#10894)
Some checks failed
Docker Dev Branch Images Build / build (Dockerfile, lc-dev, node) (push) Has been cancelled
Docker Dev Branch Images Build / build (Dockerfile.multi, lc-dev-api, api-build) (push) Has been cancelled
Publish `@librechat/client` to NPM / build-and-publish (push) Has been cancelled
Publish `librechat-data-provider` to NPM / build (push) Has been cancelled
Publish `@librechat/data-schemas` to NPM / build-and-publish (push) Has been cancelled
Docker Dev Images Build / build (Dockerfile, librechat-dev, node) (push) Has been cancelled
Docker Dev Images Build / build (Dockerfile.multi, librechat-dev-api, api-build) (push) Has been cancelled
Sync Locize Translations & Create Translation PR / Sync Translation Keys with Locize (push) Has been cancelled
Publish `librechat-data-provider` to NPM / publish-npm (push) Has been cancelled
Sync Locize Translations & Create Translation PR / Create Translation PR on Version Published (push) Has been cancelled

- Added try-catch blocks to handle errors during document deletion from the RAG API.
- Implemented logging for 404 errors indicating that the document may have already been deleted.
- Improved error logging for other deletion errors in both Firebase and Local file services.
This commit is contained in:
Danny Avila 2025-12-10 15:06:48 -05:00 committed by GitHub
parent 03c9d5f79f
commit 4a2de417b6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 36 additions and 16 deletions

View file

@ -169,14 +169,24 @@ function extractFirebaseFilePath(urlString) {
const deleteFirebaseFile = async (req, file) => { const deleteFirebaseFile = async (req, file) => {
if (file.embedded && process.env.RAG_API_URL) { if (file.embedded && process.env.RAG_API_URL) {
const jwtToken = req.headers.authorization.split(' ')[1]; const jwtToken = req.headers.authorization.split(' ')[1];
axios.delete(`${process.env.RAG_API_URL}/documents`, { try {
headers: { await axios.delete(`${process.env.RAG_API_URL}/documents`, {
Authorization: `Bearer ${jwtToken}`, headers: {
'Content-Type': 'application/json', Authorization: `Bearer ${jwtToken}`,
accept: 'application/json', 'Content-Type': 'application/json',
}, accept: 'application/json',
data: [file.file_id], },
}); data: [file.file_id],
});
} catch (error) {
if (error.response?.status === 404) {
logger.warn(
`[deleteFirebaseFile] Document ${file.file_id} not found in RAG API, may have been deleted already`,
);
} else {
logger.error('[deleteFirebaseFile] Error deleting document from RAG API:', error);
}
}
} }
const fileName = extractFirebaseFilePath(file.filepath); const fileName = extractFirebaseFilePath(file.filepath);

View file

@ -210,14 +210,24 @@ const deleteLocalFile = async (req, file) => {
if (file.embedded && process.env.RAG_API_URL) { if (file.embedded && process.env.RAG_API_URL) {
const jwtToken = generateShortLivedToken(req.user.id); const jwtToken = generateShortLivedToken(req.user.id);
axios.delete(`${process.env.RAG_API_URL}/documents`, { try {
headers: { await axios.delete(`${process.env.RAG_API_URL}/documents`, {
Authorization: `Bearer ${jwtToken}`, headers: {
'Content-Type': 'application/json', Authorization: `Bearer ${jwtToken}`,
accept: 'application/json', 'Content-Type': 'application/json',
}, accept: 'application/json',
data: [file.file_id], },
}); data: [file.file_id],
});
} catch (error) {
if (error.response?.status === 404) {
logger.warn(
`[deleteLocalFile] Document ${file.file_id} not found in RAG API, may have been deleted already`,
);
} else {
logger.error('[deleteLocalFile] Error deleting document from RAG API:', error);
}
}
} }
if (cleanFilepath.startsWith(`/uploads/${req.user.id}`)) { if (cleanFilepath.startsWith(`/uploads/${req.user.id}`)) {