Better error handling in revalidate v1 (#3094)

This commit is contained in:
Steven H
2025-04-04 14:59:14 +01:00
committed by GitHub
parent 65e9cb9d5c
commit 90ead98eaa
2 changed files with 23 additions and 5 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"gitbook": patch
---
Better error handling in cache revalidation.
@@ -25,10 +25,23 @@ export async function POST(req: NextRequest) {
);
}
const result = await revalidateTags(json.tags);
try {
const result = await revalidateTags(json.tags);
return NextResponse.json({
success: true,
stats: result.stats,
});
} catch (err: unknown) {
const message = [
err instanceof Error ? err.name : 'Internal Server Error',
...(err instanceof Error && err.message ? [err.message] : []),
...(err instanceof Error && err.cause ? [err.cause] : []),
...(err instanceof Error && err.stack ? [err.stack] : []),
].join('\n');
return NextResponse.json({
success: true,
stats: result.stats,
});
return new NextResponse(null, {
status: 500,
statusText: message,
});
}
}