Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: change related products promise type #878

Merged
merged 2 commits into from
Oct 3, 2024

Conversation

portolucas
Copy link
Contributor

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

Copy link
Contributor

Tagging Options

Should a new tag be published when this PR is merged?

  • 👍 for Patch 0.59.13 update
  • 🎉 for Minor 0.60.0 update
  • 🚀 for Major 1.0.0 update

@matheusgr
Copy link
Contributor

@portolucas Can we review this PR, or there still working to do?

One thing that comes to mind: we should log those errors, so we can monitor/take action if needed.

Also, if all promises fail, maybe we should keep current behavior: this loader should fail.

@portolucas
Copy link
Contributor Author

portolucas commented Sep 24, 2024

@portolucas Can we review this PR, or there still working to do?

One thing that comes to mind: we should log those errors, so we can monitor/take action if needed.

Also, if all promises fail, maybe we should keep current behavior: this loader should fail.

Thanks, @matheusgr ! I hope you enjoy my PR and I added some changes that consider yours suggestions.

You can review this PR.

@matheusgr matheusgr merged commit 0663326 into deco-cx:main Oct 3, 2024
1 check passed
yuriassuncx pushed a commit to yuriassuncx/apps that referenced this pull request Oct 6, 2024
* fix: change related produts promise type

* chore: add error handling for one and all products

---------

Co-authored-by: Lucas Porto <[email protected]>
yuriassuncx pushed a commit to yuriassuncx/apps that referenced this pull request Oct 16, 2024
* fix: change related produts promise type

* chore: add error handling for one and all products

---------

Co-authored-by: Lucas Porto <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug in relatedProductsLoader: Use of Promise.all Causes Loader to Fail When Any productList Call Rejects
2 participants