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

222
Views
javascript axios console log response when error

I am doing POST request with invalid data, I do it on purpose, because I am testing response messages from server. When I pass valid data, then everything is ok. Server is built on express.js

Here is my frontend code with axios:

async function submitRegister() {
    try {
      const responseFromServer = await axios.post('http://localhost:5000/register', {
        value1: value1,
        value2: value2,
        value3: value3,
        value4: value4,
        value5: value5
      }, {
        headers: {
          'Content-Type': 'application/json'
        },
        withCredentials: true
      });

      if (responseFromServer.status === 201) {
        console.log(responseFromServer);
      } else {
        console.log(responseFromServer);
      }

    } catch (error) {
      console.log(error);
    }
  }

When status 400 I want get that json response:

if (validationMessage) {
    return res.status(400).json({
        success: false,
        message: validationMessage,
        isLoggedIn: req.session.isLoggedIn
    });
}

But instead I see in console: POST http://localhost:5000/register 400 (Bad Request) Error: Request failed with status code 400

about 4 years ago · Juan Pablo Isaza
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!