Skip to content

Commit 90ead98

Browse files
authored
Better error handling in revalidate v1 (#3094)
1 parent 65e9cb9 commit 90ead98

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

.changeset/wise-baboons-develop.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"gitbook": patch
3+
---
4+
5+
Better error handling in cache revalidation.

packages/gitbook/src/app/(global)/~gitbook/revalidate/route.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,23 @@ export async function POST(req: NextRequest) {
2525
);
2626
}
2727

28-
const result = await revalidateTags(json.tags);
28+
try {
29+
const result = await revalidateTags(json.tags);
30+
return NextResponse.json({
31+
success: true,
32+
stats: result.stats,
33+
});
34+
} catch (err: unknown) {
35+
const message = [
36+
err instanceof Error ? err.name : 'Internal Server Error',
37+
...(err instanceof Error && err.message ? [err.message] : []),
38+
...(err instanceof Error && err.cause ? [err.cause] : []),
39+
...(err instanceof Error && err.stack ? [err.stack] : []),
40+
].join('\n');
2941

30-
return NextResponse.json({
31-
success: true,
32-
stats: result.stats,
33-
});
42+
return new NextResponse(null, {
43+
status: 500,
44+
statusText: message,
45+
});
46+
}
3447
}

0 commit comments

Comments
 (0)