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

461
Visualizações
TypeError: callback is not a function error callback

I keep running into this callback error while trying to test posting data to my database. I am unsure of the cause and have been trying to debug for a bit. Might be because I am passing it an error and submitError is undefined? It seems to be hooked up correctly in my method.

One of the callbacks at the bottom of the code is giving me the error. It is the catch callback telling me callback is not a function. I have this same code running fine in another project.

import axios from "axios"

import apiBaseUrl from "../../utils/apiBaseUrl.js"

export default function(title, customer, description, billed, tags, location, notes, images, jobtype, callback) {
  axios.post(`${apiBaseUrl}/jobs/create-new`, {
        title: title,
        customer: customer,
        description: description,
        billed: billed,
        tags: tags,
        location: location,
        notes: notes,
        jobtype: jobtype,
        images: images
  }, {
    withCredentials: true
  })
  .then(function(response) {
    callback(response.data)
  })
  .catch(function(error) {
    callback({submitError: true})
  })
}

This is the api side:

createNewJob: function(title, customer, description, billed, tags, location, notes, images, jobtype, callback) {
    JobModel.findOne({$or: [{title: title}, {customer: customer}]}).exec(function(error, job) {
      if (error) {
        callback({submitError: true})
      } else if (job) {
        callback({alreadyExistsError: true})
      } else {
        const arrayOfTags = tags.split(",").map(function(tag){
          return tag.trim()
        })
        const arrayOfNotes = notes.split(",").map(function(note){
          return note.trim()
        })
      }

      const newJob = new JobModel({
        id:randomstring.generate(12),
        title: title,
        customer: customer,
        description: description,
        billed: billed,
        tags: arrayOfTags,
        location: location,
        notes: arrayOfNotes,
        jobtype: jobtype,
        images: images
      })

      newJob.save(function(saveError) {
        if(saveError) {
          callback({submitError: true})
        } else {
          callback({success:true})
        }
      })
    })
  }
about 4 years ago · Juan Pablo Isaza
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