JavaScript 2025 · Promises and fetch
Handle errors in async code
Catch rejected promises and thrown errors with try and catch.
try {
const data = await load();
} catch (error) {
console.error("Failed:", error);
}
Official JavaScript 2025 documentation
More promises and fetch commands
- Fetch JSON
- POST JSON
- Time out a request
- Run promises in parallel
- Wait for all promises, whatever happens
- Pause for a while
All promises and fetch commands · JavaScript 2025 cheatsheet