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

188
Visualizações
Cannot read properties of undefined (reading '0') - ( empty error JSON response with postman)

so i'm working with Joi for validation, and i've encountered this error when trying to post with postman.

i'm follwing a tutorial, i tried to write it differently, but still have the same issue.

i'm trying to access the error message. ( first selecting the error, then the details, then the message )

in the tutorial, it looks like this

res.send(error.details[0].message)

i can see the error, but once i select details, the response is empty.

let me know if you need anything else.

Thank you in advance.

The Lord be with you and save you all, your families and friends :)

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It seems like error does not have a property called details. That's why error.details is undefined. Thus, when trying to access the element of the first index of the value undefined you'll get an error.

To fix:

  • Make sure the error object contains a property details of type Array
  • If error.details will depend on other code blocks (sometimes it is defined, sometimes it isn't), you can add a ternary expression to tell your code what to in case error.details is indeed undefined. Example:
err.details ? res.send(error.details[0].message) : res.send("error") 

Which translates to

if (err.details) { // if defined
 res.send(error.details[0].message) // Send the message from the error
} else {
 res.send("error") // Send a general message
} 
about 4 years ago · Juan Pablo Isaza 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