Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

146
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda