I still do not know what is going on inside the method that makes you think it should be throwing. But as I posted fetch() won’t reject on HTTP error status, it will only reject on network failure.
const getInvalidEndpoint = async () => {
try {
const res = await fetch("https://jsonplaceholder.typicode.com/to");
console.log(res.ok); // false
console.log(res.status); // 404
} catch (err) {
console.error("error that will not be logged", err);
}
};
getInvalidEndpoint();
Also, your use of forEach.
Note:forEach expects a synchronous function.
forEach does not wait for promises. Make sure you are aware of the implications while using promises (or async functions) as forEach callback.
const ratings = [5, 4, 5];
let sum = 0;
const sumFunction = async (a, b) => a + b;
ratings.forEach(async (rating) => {
sum = await sumFunction(sum, rating);
});
console.log(sum);
// Naively expected output: 14
// Actual output: 0