Encoding a bit off on createError?
I'm throwing an error on the server side:
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
21 Replies
never saw something like this lmfao
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
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:
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
Do you have a link in the docs for that?
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
Nah brother, I think thats a nuxt issue
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.
they overrided 500 message in this example
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?
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"
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
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
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 👍
thanks
I've never had this kind of problem, but I'll try to help
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.
response
console.log(e.message)
So.. to get MY "message" attribute
is through error.data.message
:facepalm: