JavaScript · Middle · Question 38 of 75
Will fetch reject the promise on a 404 response?
- ✓Correct answer: No: you have to check the status yourself via
res.ok - 2Yes: any 4xx or 5xx status rejects the promise with an error object
- 3Yes, but only for 5xx; 4xx responses are considered successful
Explanation
An HTTP error response is still a response. You need an explicit check: if (!res.ok) throw new Error(res.status). The promise rejects on network failure, CORS blocking or cancellation via AbortController.