Replies: 2 comments
-
maybe a |
Beta Was this translation helpful? Give feedback.
0 replies
-
That looks like a great idea actually! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Feature request
Is your feature request related to a problem? Please describe.
Next.js has API routes with built-in middlewares, such as
bodyParser
. When an error is thrown by those middlewares, Next.js sends an error response, handled bysendError
.The current implementation sends a JSON response with the error message as the body. As an example: if we send request, with
Content-Type: application/json
with an invalid JSON request body, the server responds withInvalid JSON
.However, usually APIs that I develop have a standard envelope for errors, like:
I would like to be able to keep the same response envelope for built-in middleware errors.
Describe the solution you'd like
Perhaps, we could somehow be able to tweak the
sendError
by including it in theconfig
exported in API routes?Describe alternatives you've considered
I've looked into the code to see if I could somehow monkey-patch to get around the issue temporarily, but I couldn't find a way. Another solution is to turn off all the middleware and use something like micro to have full-control, but seems overkill.
Additional context
Beta Was this translation helpful? Give feedback.
All reactions