1
JavaScriptIntermediate#browser#security
fetch is promise based, streams responses and works with async/await, but it only rejects on network failure — you must check response.ok yourself. XHR is callback based and more verbose.
const res = await fetch('/api/x');
if (!res.ok) throw new Error(res.status);
const data = await res.json();