feat: custom error page

This commit is contained in:
2026-03-25 20:54:58 +01:00
parent 783ee1b334
commit b763eb70db
3 changed files with 34 additions and 7 deletions

View File

@@ -15,16 +15,13 @@ export default defineEventHandler(async (event) => {
const path = getRequestURL(event).pathname;
const link = await db.query.links.findFirst({
let link = await db.query.links.findFirst({
where: eq(tables.links.path, path),
});
if (!link) {
throw createError({ statusCode: 404, message: "Not found" });
}
if (link.disabled) {
throw createError({ statusCode: 410, message: "This link has been disabled" });
if (!link || link.disabled) {
event.context.redirectNotFound = true;
return;
}
return sendRedirect(event, link.url, 302);