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

447
Views
How do I catch GotError [HTTPError]: Response code 404 (Not Found) in nodejs

Assuming that the url provided is wrong, the Got module raises a HTTPError, how do I catch the error? Try catch doesn't work

const got = require('got');
got(`https://www.wrongurl.com`)
                .then(response => {
                    //do stuff
                })
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I would use

got(...).then(
  response => { /* handle good response here */}, 
  error => { /* handle error here */ }
)

Simple .catch(() => { ... }) may catch an error in .then(response... part as well, that's not what you expect.

Also see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then for reference.

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!