When I try to invoke the api endpoint, I get this error:
{"statusCode":500,"message":"An unknown error occurred.","errors":["An unknown error occurred."],"stack":"TypeError: Cannot read properties of undefined (reading 'length')\n at ......./node_modules/next-api-decorators/dist/internals/handler.js:45:50\n at Array.map (<anonymous>)\n at MessageHandler.runMainLayer (/home/ashura/WebstormProjects/mysite/node_modules/next-api-decorators/dist/internals/handler.js:41:62)\n at descriptor.value (......./node_modules/next-api-decorators/dist/internals/handler.js:105:32)\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)"}
Code from the client:
function handleSubmit(e: FormEvent<HTMLFormElement>) {
e.preventDefault()
console.log(message)
fetch('/api/message', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(message)
}).then(async function (res) {
if (res.status == 200)
Swal.fire({title: 'Success', text: 'Successfully send message'})
else if (res.status == 500)
Swal.fire({icon: 'error', text: 'Something Went wrong', title: 'Error'})
})
}
(Although it results the same if I called from postman)
I get error message when trying to invoke next js api
I have an api file:
Dependencies:
When I try to invoke the api endpoint, I get this error:
{"statusCode":500,"message":"An unknown error occurred.","errors":["An unknown error occurred."],"stack":"TypeError: Cannot read properties of undefined (reading 'length')\n at ......./node_modules/next-api-decorators/dist/internals/handler.js:45:50\n at Array.map (<anonymous>)\n at MessageHandler.runMainLayer (/home/ashura/WebstormProjects/mysite/node_modules/next-api-decorators/dist/internals/handler.js:41:62)\n at descriptor.value (......./node_modules/next-api-decorators/dist/internals/handler.js:105:32)\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)"}
Code from the client:
(Although it results the same if I called from postman)