fix: avoid hiding remote lookup errors

This commit is contained in:
Tom Boullay
2026-04-27 17:22:26 +02:00
parent fd586f4185
commit 382b28103e
3 changed files with 11 additions and 16 deletions
+2 -8
View File
@@ -52,14 +52,8 @@ export async function POST(req: NextRequest) {
// --- Detect existing files and classify changes --- // --- Detect existing files and classify changes ---
const folderPath = getModelFolderPath(folderName) const folderPath = getModelFolderPath(folderName)
let remoteFileMap: Map<string, number> const remote = await getRemoteFolder(folderPath)
const remoteFileMap = new Map(remote.files.map((f) => [f.name.toLowerCase(), f.size]))
try {
const remote = await getRemoteFolder(folderPath)
remoteFileMap = new Map(remote.files.map((f) => [f.name.toLowerCase(), f.size]))
} catch {
remoteFileMap = new Map()
}
const isReplace = remoteFileMap.size > 0 const isReplace = remoteFileMap.size > 0
+2 -2
View File
@@ -215,8 +215,8 @@ export async function getRemoteFolder(
return { name: f.name, size: pointer.size } return { name: f.name, size: pointer.size }
} }
} }
} catch { } catch (err) {
// Fall through to use the original size if (!isHttpError(err) || err.status !== 404) throw err
} }
return { name: f.name, size: f.size } return { name: f.name, size: f.size }
+7 -6
View File
@@ -63,12 +63,13 @@ async function davRequest(
/** Check if a folder exists on the Nextcloud instance. */ /** Check if a folder exists on the Nextcloud instance. */
export async function folderExists(path: string): Promise<boolean> { export async function folderExists(path: string): Promise<boolean> {
try { const res = await davRequest('PROPFIND', path + '/', null, { Depth: '0' })
const res = await davRequest('PROPFIND', path + '/', null, { Depth: '0' })
return res.status >= 200 && res.status < 300 if (res.status === 404) return false
} catch { if (res.status >= 200 && res.status < 300) return true
return false
} const text = await res.text().catch(() => '')
throw new Error(`PROPFIND ${path} failed (${res.status}): ${text.slice(0, 200)}`)
} }
/** /**