Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

145
Visualizações
How to catch specific error message in javascript from backend

From backend I am getting specific error message during the post request. How may I get this message in javascript?

catch(err => console.log('error', err.response.data)) With this code I am getting just the type of the error, but I need the message which I throw from backend. F.ex throw ConflictException("The name is already exist"). I need get the following message "The name is already exist", not just the the type.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

<!DOCTYPE html>
<html>
<body>
<script>
try {
 throw new Error('Custom Exception');
}
catch(err) {
 if(err.message){
 console.log('inside if & error message as follow : ',err.message);
 }else {
 console.log('inside else');
 console.log(err);
 }
 
}
</script>
</body>
</html>

Above is for demonstration purpose, if it still not working then try

catch(err => console.log('error', err?.message));
about 4 years ago · Juan Pablo Isaza Relatório

0

Caught errors generally have a message field stored at error?.message or if you using things like Axios or other API requests, error messages are generally at error.response?.data?.message!

Note: ?. is an optional chaining to prevent other errors like Can not read properties of undefined, reading x

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda