h3
h3 copied to clipboard
Empty error message
Environment
Node v18.18.2 Nuxt v3.11.2 Mittwald Hosting (German Hosting Provider)
Reproduction
It only happens on the external hosting service therefor I cannot provide a reproduction ... Everywhere else I tested it worked fine.
Describe the bug
e.message does not include the statusMessage from createError
Serverside
if (alreadyExists) return sendError(event, createError({ statusCode: 400, statusText: 'Title already exists.' }))
(I also tried with statusMessage, but jsDocs states statusText is current)
Clientside (Nuxt)
console.log(e.message)
On every other env the message is shown correctly with "Title already exists.". Not on Mittwald. Though the response shows the statusMessage.
Is it somehow possible to get to the raw error object, shown in the Response panel?
It's not existing in the error object console.log(e)
Additional context
No response
Logs
No response
You can access error messages from the frontend but only in development environment, is this correct? Because that is my problem. Did you find a solution?
My solution is a workaround: I used custom statusCodes (480, 481, 482) and moved the error message to the frontend.
Based on this message, I started trying using data for the error message which initially didn't work, but then I accidentally found something which does work. I send the error from backend like:
throw createError({ statusCode: 422, statusMessage: "no_username" })
and then receive on frontend like:
try {
// some code
} catch (error) {
errorMessage = error.data.message
}
Try it.