ARTICLE AD BOX
I asked the Stack Overflow AI already: link, but I didn't found the answer helpful.
My question is: I want to fetch other content with JavaScript, but return null if a 404 error occurs.
Example:
function fetchJsonResultsOrNull(index) { return fetch('headlines-' + index + '.json') .then(function (response) { if (response.status == 200) { return response.json(); } throw new Error('Network response was not ok.'); }) .then(function (json) { return json.results; }) .catch(function (error) { console.log('Fetch error:', error); return null; }); }but in the browser console still the 404 error occurs.
