diff --git a/gateway/src/index.ts b/gateway/src/index.ts index ef12f8e..b071867 100644 --- a/gateway/src/index.ts +++ b/gateway/src/index.ts @@ -431,7 +431,13 @@ const requestHandler = (req: IncomingMessage, res: ServerResponse) => { requestUrl.pathname === "/api/store/themes" || requestUrl.pathname.startsWith("/api/store/themes/") ) { - await handleStore(req, res, requestUrl.pathname); + await handleStore(req, res, requestUrl.pathname).catch((err) => { + console.error("[store] Request failed:", err); + if (!res.headersSent) { + res.writeHead(500, { "Content-Type": "application/json" }); + res.end(JSON.stringify({ error: "internal" })); + } + }); return; } diff --git a/gateway/src/store.ts b/gateway/src/store.ts index 3eed178..9312e23 100644 --- a/gateway/src/store.ts +++ b/gateway/src/store.ts @@ -117,7 +117,11 @@ async function loadStoreThemes(): Promise { if (storeCache) return storeCache; try { storeCache = JSON.parse(await readFile(STORE_DATA_FILE, "utf-8")) as StoreTheme[]; - } catch { + } catch (err) { + // Only a missing file means "no themes yet". Anything else (unreadable, + // corrupt) must fail loudly - treating it as empty would let the next + // submission overwrite every stored theme. + if ((err as NodeJS.ErrnoException).code !== "ENOENT") throw err; storeCache = []; } return storeCache;