I'd like to use a Promise chain to load some data before starting my application. So, I'll have something like:
fetch('path/to/data.json')
.then((response) => response.json())
.then((data) => {
console.log(`Hey cool, we're done w/ the promise chain here`);
startApp(data);
})
.catch((error) => console.error(`Error in promise chain: ${error}`));
It does work—but with this setup, any errors in my startApp
function (or any subsequent functions down the line) get handled within the Promise chain, which seems wrong.
The Promise examples I find typically end with a console log in the last then()
of the chain, so they're not terribly instructive about this.
- Is the way I've set things up actually fine?
- If not, how can I wait til the end of the promise chain to call the
startApp
function without still being inside the chain?