Send asynchronous browser requests with fetch, XMLHttpRequest, JSON, errors, and progressive UI.
Lessons
Branch on 2xx, 4xx, and 5xx responses.
Reading Status Codes is easiest to learn by reading the example, changing it, and observing the result.
const res = await fetch('/api/lessons');
if (res.status >= 200 && res.status < 300) {
console.log('Success', await res.json());
} else if (res.status === 404) {
console.log('Not found');
} else if (res.status >= 500) {
console.log('Server error');
}Practice the Reading Status Codes example in a small scratch file, then explain what changed and why.