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

180
Views
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 answers
Answer question

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 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!