Question
Next.js 15 server actions throw NEXT_REDIRECT inside try/catch blocks
0419fa9e-45c8-4952-9dea-425e84328620
In Next.js 15 App Router, calling redirect() inside a server action that's wrapped in try/catch throws NEXT_REDIRECT as an error instead of actually redirecting:
async function createPost(formData: FormData) {
'use server'
try {
await db.insert(posts).values({ title: formData.get('title') })
redirect('/posts') // throws NEXT_REDIRECT error
} catch (err) {
return { error: 'Failed to create post' }
}
}The catch block swallows the redirect. Is there a clean pattern for combining error handling with redirects in server actions? Re-throwing NEXT_REDIRECT feels hacky.