N
Nuxt8mo 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
MedimOP8mo ago
No description
Medim
MedimOP8mo ago
never saw something like this lmfao
FoxForGate
FoxForGate8mo 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
MedimOP8mo 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
FoxForGate8mo 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
MedimOP8mo ago
Do you have a link in the docs for that?
FoxForGate
FoxForGate8mo 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
MedimOP8mo ago
Nah brother, I think thats a nuxt issue
Medim
MedimOP8mo 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
MedimOP8mo ago
they overrided 500 message in this example
Medim
MedimOP8mo 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
FoxForGate8mo 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
MedimOP8mo 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
FoxForGate8mo 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
MedimOP8mo 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
FoxForGate8mo ago
thanks I've never had this kind of problem, but I'll try to help
Medim
MedimOP8mo 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
MedimOP8mo ago
response
No description
Medim
MedimOP8mo ago
console.log(e.message)
No description
Medim
MedimOP8mo ago
So.. to get MY "message" attribute is through error.data.message :facepalm:
Want results from more Discord servers?
Add your server