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

145
Views
How to use or operator on object when having error

So I tried to give null for the error message, but it shows

 if(err){
            res.status(403).json({
              emailErr: err.errors.email.message || null,
              userErr: err.errors.username.message || null,
            });

TypeError: Cannot read property 'message' of undefined
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Normally, JavaScript errors out if you try to access a property on undefined like in this lookup chain. You can use optional chaining to tell JavaScript to expect it:

if (err) {
    res.status(403).json({
        emailErr: err.errors.email?.message || null,
        userErr: err.errors.username?.message || null,
    });
}
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!