FIX: Implement proper 404 error handling for missing files in SSH file size check
- Fix case-sensitive string matching for "no such file or directory" errors - Return 404 status with fileNotFound flag when files don't exist - Enable automatic cleanup of deleted files from recent/pinned lists - Improve error detection in file size check phase before file reading
This commit is contained in:
@@ -569,10 +569,20 @@ app.get("/ssh/file_manager/ssh/readFile", (req, res) => {
|
|||||||
|
|
||||||
sizeStream.on("close", (sizeCode) => {
|
sizeStream.on("close", (sizeCode) => {
|
||||||
if (sizeCode !== 0) {
|
if (sizeCode !== 0) {
|
||||||
|
// Check if it's a file not found error (case-insensitive)
|
||||||
|
const errorLower = sizeErrorData.toLowerCase();
|
||||||
|
const isFileNotFound = errorLower.includes("no such file or directory") ||
|
||||||
|
errorLower.includes("cannot access") ||
|
||||||
|
errorLower.includes("not found") ||
|
||||||
|
errorLower.includes("resource not found");
|
||||||
|
|
||||||
fileLogger.error(`File size check failed: ${sizeErrorData}`);
|
fileLogger.error(`File size check failed: ${sizeErrorData}`);
|
||||||
return res
|
return res
|
||||||
.status(500)
|
.status(isFileNotFound ? 404 : 500)
|
||||||
.json({ error: `Cannot check file size: ${sizeErrorData}` });
|
.json({
|
||||||
|
error: `Cannot check file size: ${sizeErrorData}`,
|
||||||
|
fileNotFound: isFileNotFound
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const fileSize = parseInt(sizeData.trim(), 10);
|
const fileSize = parseInt(sizeData.trim(), 10);
|
||||||
|
|||||||
Reference in New Issue
Block a user