Skip to content
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

Empty error message #823

Open
fabianwohlfart opened this issue Jul 10, 2024 · 3 comments
Open

Empty error message #823

fabianwohlfart opened this issue Jul 10, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@fabianwohlfart
Copy link

fabianwohlfart commented Jul 10, 2024

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?
Bildschirmfoto 2024-07-10 um 11 53 23

It's not existing in the error object console.log(e)
Bildschirmfoto 2024-07-10 um 12 04 52

Additional context

No response

Logs

No response

@fabianwohlfart fabianwohlfart added the bug Something isn't working label Jul 10, 2024
@kamran-12
Copy link

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?

@fabianwohlfart
Copy link
Author

My solution is a workaround: I used custom statusCodes (480, 481, 482) and moved the error message to the frontend.

@kamran-12
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants