diff --git a/app/api/upload/git/route.ts b/app/api/upload/git/route.ts index 1b4da51..ae51e7d 100644 --- a/app/api/upload/git/route.ts +++ b/app/api/upload/git/route.ts @@ -52,14 +52,8 @@ export async function POST(req: NextRequest) { // --- Detect existing files and classify changes --- const folderPath = getModelFolderPath(folderName) - let remoteFileMap: Map - - try { - const remote = await getRemoteFolder(folderPath) - remoteFileMap = new Map(remote.files.map((f) => [f.name.toLowerCase(), f.size])) - } catch { - remoteFileMap = new Map() - } + const remote = await getRemoteFolder(folderPath) + const remoteFileMap = new Map(remote.files.map((f) => [f.name.toLowerCase(), f.size])) const isReplace = remoteFileMap.size > 0 diff --git a/lib/github.ts b/lib/github.ts index 3874002..0cf46bd 100644 --- a/lib/github.ts +++ b/lib/github.ts @@ -215,8 +215,8 @@ export async function getRemoteFolder( return { name: f.name, size: pointer.size } } } - } catch { - // Fall through to use the original size + } catch (err) { + if (!isHttpError(err) || err.status !== 404) throw err } return { name: f.name, size: f.size } diff --git a/lib/nextcloud.ts b/lib/nextcloud.ts index c22d3b7..d5d6977 100644 --- a/lib/nextcloud.ts +++ b/lib/nextcloud.ts @@ -63,12 +63,13 @@ async function davRequest( /** Check if a folder exists on the Nextcloud instance. */ export async function folderExists(path: string): Promise { - try { - const res = await davRequest('PROPFIND', path + '/', null, { Depth: '0' }) - return res.status >= 200 && res.status < 300 - } catch { - return false - } + const res = await davRequest('PROPFIND', path + '/', null, { Depth: '0' }) + + if (res.status === 404) return false + if (res.status >= 200 && res.status < 300) return true + + const text = await res.text().catch(() => '') + throw new Error(`PROPFIND ${path} failed (${res.status}): ${text.slice(0, 200)}`) } /**