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

186
Visualizações
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 Respostas
Responde à pergunta

0

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

May be catching error on your axios is wrong try this

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