How can I show partial results when only some requests succeed?
Quick answer
Treat each independent request as its own outcome instead of making the whole batch succeed or fail together. In JavaScript, Promise.allSettled() returns a fulfilled or rejected outcome for every input, in input order; map each outcome back to its item, then show successes alongside clearly labeled failures. [S1] Mark the overall view as partial if any item failed, and explain which items need attention.
The question, the details, the next step.
A practical checklist
Use
Promise.allSettled()when independent requests should each report an outcome.Keep a stable item ID or label paired with every request.
Render each success and failure separately, with a plain-language failure message.
Show an overall partial-results label whenever at least one item failed.
Check all-success, all-failure, and mixed outcomes, including different completion orders.
A few more useful answers
Does `Promise.allSettled()` return results in the order requests finish?
No. It returns one outcome per input in input order, regardless of completion order. Preserve the input-to-item mapping so each outcome is shown beside the right item. [S1]
Does `Promise.allSettled()` decide what the user-facing error should say?
No. It reports a rejected outcome and its reason, but your application chooses the message and how to display it. [S1]
Sources
References used for this guide.
- [S1] Promise.allSettled() — JavaScript | MDN developer.mozilla.org · Checked
- [S2] Promise.all() — JavaScript | MDN developer.mozilla.org · Checked
