3 ms·
Now you're pretty far out of a discussion about handling promise rejections, and into a discussion about product UX and feature design... "There's no point sho
by horsawlarway 4y ago
Now you're pretty far out of a discussion about handling promise rejections, and into a discussion about product UX and feature design...
"There's no point showing additional chapters if an earlier one fails." <- This is not always true, and heavily dependent on what the use case is. For a book? sure. for a manual or textbook? Much less sure.
The approach works just fine either way, though - if you don't want to display additional chapters if one fails, you can do so easily by just including a "success" field (or anything similar) in the object that appendChapters expects, and break if needed when you hit that. (although again - you'd probably be better served by displaying a user readable error and offering a button to retry, and then displaying the rest of the content so you don't have to fetch it all a second time).
Alternatively, you can also have appendChapters throw, or if you really want, you can still leave the promise rejection - but leaving the rejection or throwing at this spot means you're making a contract that calls for `try/catch` to use without unhandled rejections.
That's the whole deal with async await. You're trading the formatting of .then().catch() for try{}catch(){}.
if you don't like writing try/catch blocks, either structure the contract so that the promise doesn't reject (at least for expected error cases), or use the traditional .then().catch().