A promise represents the eventual completion or failure of an asynchronous operation. With Fetch, it resolves to a Response; an HTTP error status still resolves, so check response.ok or response.status yourself. section 12.1.1
Handle rejections explicitly: attach catch() to a promise chain, or use try/catch around await inside an async function. Unhandled rejections trigger the global unhandledrejection event. section 5.9.3
Load and check JSON
Await fetch(), throw when response.ok is false, then parse the response with response.json(). Catch failures at the call site to avoid unhandled rejections. section 5.9.3 section 12.1.1
Listing 12.1 A reusable helper for JSON requests
async function requestJSON(url, options = {}) {
const { headers, ...fetchOptions } = options;
const response = await fetch(url, {
...fetchOptions,
headers: {
Accept: "application/json",
...headers,
},
});
if (!response.ok) {
throw new Error(`Request failed with ${response.status}`);
}
return response.json(); #1
}
See a reusable JSON request helper that sets headers, checks response status, and returns the parsed body. section 12.1.1
Programmatic navigation can return promises for different milestones: committed signals that the URL and current entry changed, while finished signals that navigation work—including an intercepted route handler—has completed. section 11.2










