In SvelteKit,
-use Client-side redirect
- Or just… don’t use try/catch 😁
If you insist & still want try/catch:
→
@KeO_Coder
redirect() inside a try/catch throws a special error that MUST bubble up to the framework. If you catch it without re-throwing → the redirect dies. Server redirects() only break if you catch them. Easiest ways to dodge this: -use Client-side redirect
- Or just… don’t use try/catch 😁
If you insist & still want try/catch:
try {
throw redirect(302, '/login');
} catch (err) {
console.log("caught it lol");
// redirect dies here ❌
}→
try {
throw redirect(302, '/login');
} catch (err) {
if (err.status) throw err; // redirect survives ✔️
}@KeO_Coder
👍2