N
Nuxt2mo ago
Medim

Encoding a bit off on createError?

I'm throwing an error on the server side:
throw createError({
statusCode: 401,
statusMessage: "Usuário já existe",
})
throw createError({
statusCode: 401,
statusMessage: "Usuário já existe",
})
And on the front I got a try catch that successfully catches the error, but on logging the error.statusMessage and error.message it misses characters with diacritics, it returns "Usurio j existe" instead of "Usuário já existe" Am I doing something wrong? On the Network tab, on the error body, statusmessage is correct tho
No description
21 Replies
Medim
Medim2mo ago
No description
Medim
Medim2mo ago
never saw something like this lmfao
FoxForGate
FoxForGate2mo ago
olha um BR aqui, vou lhe enviar a mensagem em ingles para a galera poder entender tmb kkk The problem is that "statusMessage" is reserved for the message related to the error code, so for example, if you use the 401 code, the correct thing is for your statusMessage to be "Unauthorized", texts of the statusMessage type do not support accentuation, for this reason this problem is occurring, try using the statusMessage according to your codeStatus, or do not use accents in it If I'm not mistaken, you can just pass "status Code" and it will automatically set the statusMessage according to
Medim
Medim2mo ago
What about “message” then It also removes diacritics There’s must be a way to retrieve error info from server to the user in my native language without me having to write a “getMessageFromStatus” function Also, why would it let me edit in the first place? If i were to translate “Unauthorized” to my native lang as “Não Autorizado” it would also eat up the ã it doesn’t makes sense :squigglethink:
FoxForGate
FoxForGate2mo ago
yes, you can return "data", this being a parameter accepted by createError(), and in it you can pass an object with information, such as the error message in Portuguese
Medim
Medim2mo ago
Do you have a link in the docs for that?
FoxForGate
FoxForGate2mo ago
because there are cases in which you create internal status codes, I have already worked with APIs of this type, for example, it can return an 809 code, however this does not exist in our official http response list, for this reason you would have to create a statusMessage for the same
Medim
Medim2mo ago
Nah brother, I think thats a nuxt issue
Medim
Medim2mo ago
Handling Errors in Nuxt 3
This article explores errors you may face in building your Nuxt 3 application, and how you can handle these errors to make your application rock solid.
Medim
Medim2mo ago
they overrided 500 message in this example
Medim
Medim2mo ago
If i were to do the same but in portuguese I would have the same issue do you mean the ‘data’ property or the ‘cause’ property?
FoxForGate
FoxForGate2mo ago
sim como eu disse, voce pode alterar a informação, porem ela tem como objetivo ser um indicativo, um curto texto de uma ou duas palavras, não é correto utilizar ele para passar a informação que vai ser exibida para o usuário, para este objetivo pode se utilizar "data", ou "message"
Medim
Medim2mo ago
sim brother, mas o “message” também acontece a mesma coisa se tu usa o “statusMessage” mostra um aviso no console pra usar o “message” pra ser descritivo e que ele vai ser sanitizado em uma atualização futura mas o mesmo erro acontece
FoxForGate
FoxForGate2mo ago
ahhh agora sim entendi the image you sent previously only has the statusMessage, can you send it showing the message so we can see the erro
Medim
Medim2mo ago
I tried creating a codesandbox and it didn’t even print the error.message, it printed a blank line lmao gonna create a reproduction tomorrow 👍
FoxForGate
FoxForGate2mo ago
thanks I've never had this kind of problem, but I'll try to help
Medim
Medim2mo ago
Carlos Eduardo Medim
StackBlitz
Nuxt - Starter (forked) - StackBlitz
Create a new Nuxt project, module, layer or start from a theme with our collection of starters.
Medim
Medim2mo ago
response
No description
Medim
Medim2mo ago
console.log(e.message)
No description
Medim
Medim2mo ago
So.. to get MY "message" attribute is through error.data.message :facepalm: