-
Notifications
You must be signed in to change notification settings - Fork 64
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
Possible to catch missing export default router.handler()
#202
Comments
I get this error too. I wish syntax like before
|
If you are using the NextJS App/Router system, you can handle exceptions as follows: import type { NextRequest } from "next/server";
import { createEdgeRouter, NextHandler } from "next-connect";
const router = createEdgeRouter<NextRequest, {}>();
router.get((request, context, next) => {
if (true) {
// force an exception to show custom error message
throw new Error('This is my error message');
}
return Response.json({ message: 'hello world' }, {
status: 200
});
});
export async function GET(request: NextRequest, context: {}) {
// trying to run the request but managing if there are any exceptions
return router.run(request, context).catch((error) => {
const errorMessage = error.message ?? 'Interanal Server Error Message';
return Response.json({ message: errorMessage }, {
status: 500
});
});
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With the new changes of v1, I found myself forgetting a couple of times to call
.handler()
whenexport default router
.This leads to Next.js throwing
TypeError: resolver not a function
. Is it somehow possible to catch this issue and provide a more user-friendly error message?I'm aware of that I'm asking a lot here, since this Next.js scope related.
The text was updated successfully, but these errors were encountered: