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

184
Views
Error , Console log the axios network response

1.I'm working on an backend API but at some point I need to get user data from another API. I am trying to use Axios to make http request in order to do that. The request return the result in the browser as expected but the problem is that I can't display console log in the terminal. It doesn't show anything even though I asked the program to do so. Is there a problem probably with my code?

2.Error message =>>> POST http://localhost:8000/api/register 400 (Bad Request) Error: Request failed with status code 400`

const handleSubmit = async () => {
  //e.preventDefault();
  try 
  {
    // console.log(name, email, password, secret);
    const { data } = await axios.post("http://localhost:8000/api/register", {
      name,
      email,
      password,
      secret,
    });
    setOk(data.ok); //useState component
  } 
  catch (error) {
    **strong text**
    console.log(error.response.data);
  }

 }

import User from '../models/user' //import{ hashPassword, comparePassword } from '../helpers/auth'

    export const register = async (req,res) => {
        //console.log('Register endpoint =>', req.body)
        //to make this work make express.json is applied in the above middleware
    
        //console.log error to debug code
    
    
        const {name, email, password, secret} = req.body;
    
        //validation
        if(!name) return res.status(400).send('Name is required')
        if(!password  || password.length < 6) return res.status(400).send('Password is 
         short 
        or password is not entered')
        if(!secret) return res.status(400).send('Answer is required')
        //The above code is for validation purpose to make sure data is correctly 
        entered

        const exist = await User.findOne({email })
    
    
        if(exist) return res.status(400).send('Email is taken')
   }
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

.catch(error => {
console.log(error)
})

May be catching error on your axios is wrong try this

about 4 years ago · Santiago Gelvez 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!