Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

144
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!