While you could have used a Promise.all for fetching these two API endpoints, your reasoning separates code by concepts. First, API calls, then error checking. When you are using async/await thou, the code is stuck on the calls until getting the response or the errors, but in this code piece, you are executing both calls and waiting for the first to finish to start the next, and then checking errors.
A better approach would have been Promise.all, or even, check for errors right after each call. There is no need for a second call to the API if there was an error in the first one, right?
Unless, you had a separated state per category, and used setFatalError with the error and the category.
https://github.com/misterbl/star-wars-directory/blob/a760df28e6efb05ceae6a46bf4b4ed9e9e345d12/src/actions/thunks/searchFilmsAndPeople.ts#L18
While you could have used a
Promise.all
for fetching these two API endpoints, your reasoning separates code by concepts. First, API calls, then error checking. When you are using async/await thou, the code is stuck on the calls until getting the response or the errors, but in this code piece, you are executing both calls and waiting for the first to finish to start the next, and then checking errors.A better approach would have been Promise.all, or even, check for errors right after each call. There is no need for a second call to the API if there was an error in the first one, right? Unless, you had a separated state per category, and used
setFatalError
with the error and the category.