Handle redirect errors in routes and actions

The commit introduces a check for redirect errors in routes and actions modules to provide better error handling. It imports `isRedirectError` from 'next/dist/client/components/redirect' and uses it to check if an error is a redirect error, in which case re-throws the error. A minor modification was also made in the creation of the team account's home path variable.
This commit is contained in:
giancarlo
2024-04-28 01:04:55 +07:00
parent 70a7778d31
commit 25687bb497
3 changed files with 12 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
import 'server-only';
import { isRedirectError } from 'next/dist/client/components/redirect';
import { redirect } from 'next/navigation';
import type { User } from '@supabase/supabase-js';
@@ -81,6 +82,10 @@ export function enhanceAction<
// pass the data to the action
return await fn(data, user);
} catch (error) {
if (isRedirectError(error)) {
throw error;
}
// capture the exception
await captureException(error);