Safely awaits a promise, catching any errors.
The resolved type of the promise.
The type of the error.
The promise to await.
Optional
Options for error handling.
A Promise of a Result containing either the resolved value or the caught error.
const [error, data] = await safeAsync( fetch("https://api.example.com/data").then((res) => res.json()),);if (error) { console.error(error.message);} else { console.log(data);} Copy
const [error, data] = await safeAsync( fetch("https://api.example.com/data").then((res) => res.json()),);if (error) { console.error(error.message);} else { console.log(data);}
Safely awaits a promise, catching any errors.