NextResponse error handling. Unable to access error.message on the client in production.
Unanswered
Persian posted this in #help-forum
PersianOP
Hello! I'm having trouble figuring out how to properly handle errors on a route.js file with NextResponse. I am returning a response with error status and on the client I am handling the error dynamically depending on the status and error message.
My approaches have been the following:
1.
a. This approach works when developing locally. When I run a try catch on the client, the error object successfully displays an error.message = 'Error message here.'
b. When pushing to production I get an empty error message on the client.
2.
a. This approach also gives me an empty error message on the client.
3.
a. This approach also gives me an empty error message on the client.
My approaches have been the following:
1.
return NextResponse.json({},{status: 403, statusText: 'Error message here.'})a. This approach works when developing locally. When I run a try catch on the client, the error object successfully displays an error.message = 'Error message here.'
b. When pushing to production I get an empty error message on the client.
2.
return NextResponse.json({error: 'Error message here'}, {status: 403})a. This approach also gives me an empty error message on the client.
3.
return NextResponse.json({message: 'Error message here'}, {status: 403})a. This approach also gives me an empty error message on the client.