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

593
Views
JS fetch() | How to hide console error on 404?

I'm using javascripts fetch() method to check if a file on the server exists, if not i want to fallback to fetching another default file. In this article I allready learned that JS does not throw an error if the request results in an 404 Error, but sets response.ok to false.

So my code looks like this now:

let resp;

resp = await fetch("url1"); //check for custom file at url1
if (!resp.ok) { resp = await fetch("url2"); } //if not found use default file at url2

It work's as expected, but: if the first request returns a 404-Status Code the console allways shows an error for the 404 Response. I dont want to see the Error in the console because it looks like an application error, but just means that the default file was loaded... Any Ideas how to fix this? I'm using Chrome and it looks like this:

Screenshot - error in Chrome's console

about 4 years ago · Juan Pablo Isaza
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!