Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redirect inside try/catch block in server action throws NEXT_REDIRECT error #59930

Closed
1 task done
renanleonel opened this issue Dec 25, 2023 · 3 comments
Closed
1 task done
Labels
bug Issue was opened via the bug report template. locked

Comments

@renanleonel
Copy link

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/youthful-hopper-h96xf2?file=%2Flib%2Factions.ts%3A32%2C20

To Reproduce

  1. Start application with next dev
  2. fill the form
  3. next redirect error

Current vs. Expected behavior

expected: redirect to /info
curr: error in redirecting

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

System:
    OS: Windows 11
  Binaries:
    Node: 21.1.0 
    pnpm: 8.12.0 
  npmPackages:
    next: ^14.0.4 => 14.0.4
    next-auth: 5.0.0-beta.4 => 5.0.0-beta.4
    react: 18.2.0 => 18.2.0

Which area(s) are affected? (Select all that apply)

App Router

Additional context

No response

@renanleonel renanleonel added the bug Issue was opened via the bug report template. label Dec 25, 2023
@DenisBytes

This comment has been minimized.

@zce
Copy link
Contributor

zce commented Jan 5, 2024

This is not a bug.

Because APIs such as redirect and notFound interrupt program execution by throwing exceptions that Next.js can handle.

You may need to move them outside of the try catch.

Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. locked
Projects
None yet
Development

No branches or pull requests

3 participants