Wraps an async function to return a ResultAsync instead of throwing errors.
The async function type.
The type of the error.
The async function to wrap.
Optional
Options for error handling.
An async function that returns a ResultAsync.
const safeFetch = fromAsyncThrowable(fetch);const [error, response] = await safeFetch("https://api.example.com/data");if (error) { console.error(error.message);} else { const data = await response.json(); console.log(data);} Copy
const safeFetch = fromAsyncThrowable(fetch);const [error, response] = await safeFetch("https://api.example.com/data");if (error) { console.error(error.message);} else { const data = await response.json(); console.log(data);}
Wraps an async function to return a ResultAsync instead of throwing errors.