You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With the new changes of v1, I found myself forgetting a couple of times to call .handler() when export 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:
If you are using the NextJS App/Router system, you can handle exceptions as follows:
importtype{NextRequest}from"next/server";import{createEdgeRouter,NextHandler}from"next-connect";constrouter=createEdgeRouter<NextRequest,{}>();router.get((request,context,next)=>{if(true){// force an exception to show custom error messagethrownewError('This is my error message');}returnResponse.json({message: 'hello world'},{status: 200});});exportasyncfunctionGET(request: NextRequest,context: {}){// trying to run the request but managing if there are any exceptionsreturnrouter.run(request,context).catch((error)=>{consterrorMessage=error.message??'Interanal Server Error Message';returnResponse.json({message: errorMessage},{status: 500});});}
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: