next.js
34524f01 - Fix Server Action error logs for unhandled POST requests (#64315)

Commit
1 year ago
Fix Server Action error logs for unhandled POST requests (#64315) ## Why Currently, Server Action handlers are just normal routes and they accepting POST requests. The only way to differentiate a normal request (page access, API route, etc.) from a Server Action request is to check that if it's a POST and has a Server Action ID set via headers or body (e.g. `multipart/form-data`). Usually, for existing page and API routes the correct handlers (page renderer, API route handler) will take precedence over Server Action's. But if the route doesn't exist (e.g. 404) it will still go through Server Action's handler and result in an error. And we're eagerly logging out that error because it might be an application failure, like passing a wrong Action ID. ## How In this PR we are making sure that the error is only logged if the Action ID isn't `null`. This means that it's an intentional Server Action request with a wrong ID. If the ID is `null`, we just handle it like 404 and log nothing. Fixes #64214. Closes NEXT-3071
Author
Parents
Loading