Skip to content

Commit dd89316

Browse files
authored
Only log prefetch and read errors when the debug flag is enabled (#118)
* fix: only log prefetch read errors when debug mode is enabled * fix: only log page data read errors when debug mode is enabled --------- Co-authored-by: an2n <>
1 parent 4d2af02 commit dd89316

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

packages/nextjs-cache-handler/src/instrumentation/register-initial-cache.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,14 @@ export async function registerInitialCache(
291291
)
292292
.then((data) => (isAppRouter ? data : (JSON.parse(data) as object)))
293293
.catch((error) => {
294-
console.warn(
295-
"[CacheHandler] [%s] %s %s",
296-
"registerInitialCache",
297-
"Failed to read page data, assuming it does not exist",
298-
`Error: ${error}`,
299-
);
294+
if (debug) {
295+
console.warn(
296+
"[CacheHandler] [%s] %s %s",
297+
"registerInitialCache",
298+
"Failed to read page data, assuming it does not exist",
299+
`Error: ${error}`,
300+
);
301+
}
300302

301303
return undefined;
302304
}),
@@ -305,12 +307,14 @@ export async function registerInitialCache(
305307
.readFile(`${pathToRouteFiles}.prefetch.rsc`, "utf-8")
306308
.then((data) => data)
307309
.catch((error) => {
308-
console.warn(
309-
"[CacheHandler] [%s] %s %s",
310-
"registerInitialCache",
311-
"Failed to read page prefetch data, assuming it does not exist",
312-
`Error: ${error}`,
313-
);
310+
if (debug) {
311+
console.warn(
312+
"[CacheHandler] [%s] %s %s",
313+
"registerInitialCache",
314+
"Failed to read page prefetch data, assuming it does not exist",
315+
`Error: ${error}`,
316+
);
317+
}
314318

315319
return undefined;
316320
})

0 commit comments

Comments
 (0)