fix: change related products promise type #878
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What is this Contribution About?
Brief Description of Changes:
This pull request enhances the relatedProductsLoader function by improving its error handling mechanism. Previously, the loader used Promise.all to fetch related products in batches, which caused the entire loader to fail if any single productList call rejected due to an error (e.g., API failure or network issue). This behavior led to unhandled promise rejections and potential application instability.
To address this issue, the following changes have been made:
Replaced Promise.all with Promise.allSettled: This allows all promises to complete regardless of individual failures. It prevents the loader from rejecting entirely when a single promise fails.
Result Handling: The loader now filters the fulfilled promises to collect successful results and handles rejected promises by logging the errors. This ensures that the loader returns a consistent type (Product[] | null) without propagating errors unnecessarily.
Error Logging: Added console error logs for rejected promises to aid in debugging and monitoring of failed requests.
These enhancements improve the robustness and resilience of the relatedProductsLoader, ensuring that applications using it can handle partial failures gracefully without experiencing complete breakdowns in functionality.
Issue Link