Calling function NODEJS returns 400

Asked

Viewed 27 times

1

I have a REST method that calls a Function. This Function checks if a vaccine already exists in the database, otherwise creates and returns to the method that called it. However, when calling the REST method I am receiving an error 400.

In the console nothing is recorded. Someone could indicate the error?

function getVaccineByName(name, dose, avoidedDiseases) {

  Vaccine.find({ name: name }).then((existingVaccine) => {
    if (existingVaccine) {
      return existingVaccine
    } else {
      const newVaccine = new Vaccine({
        name: name,
        date: new Date().toString(),
        dose: dose,
        avoidedDiseases: avoidedDiseases
      })
    
      newVaccine.save()
        .then(vaccine => {
          return vaccine
        })
        .catch(err => JSON.stringify(err))
    }
  }).catch(err => {
    console.log('inner err');
    throw err
  })
}

  • That answer (400) means that the server cannot understand your request, as there is an invalid syntax or structure. We need more information to understand the error, but I believe it may be an error in the request, in the structure of the sending object, I believe.

  • I may be wrong, but nothing comes up if you put one console.log() in the err here: .catch(err => JSON.stringify(err)) instead of JSON.stringify?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.