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(api): Prevent throw error, when skus is empty #1220

Closed
wants to merge 2 commits into from

Conversation

igorbrasileiro
Copy link
Contributor

@igorbrasileiro igorbrasileiro commented Apr 8, 2022

What's the purpose of this pull request?

Prevent throw error when SKUs is empty, also missingSkus will be empty.

How it works?

How to test it?

base.store Deploy Preview

References

@igorbrasileiro igorbrasileiro requested a review from a team as a code owner April 8, 2022 15:19
@codesandbox-ci
Copy link

codesandbox-ci bot commented Apr 8, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 274f879:

Sandbox Source
Store UI Typescript Configuration

Copy link
Member

@eduardoformiga eduardoformiga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested it simulating the error and I think it's not working as expected since we won't have the missing SKUs on the error message.
"message": "Search API did not return the following skus: ",

Logs from the main local variables:
Screen Shot 2022-04-08 at 12 58 15

So I have a suggestion:

  1. Maps the skus object as a key/value object.
const skus = skuIds.map((skuId) => ({
      key: skuId,
      value: skuBySkuId[skuId],
    }))
  1. The missingSkus mapping the new key (sku).
const missingSkus = skus.filter((sku) => !sku.value).map((sku) => sku.key)
  1. Keeps the original if and return the skus values:
if (missingSkus.length > 0) {
//...
}

return skus.map((sku) => sku.value)

logs after changes:
Screen Shot 2022-04-08 at 13 10 48

error message:
"message": "Search API did not return the following skus: 1010",

We can pair programming to discuss more :)

@igorbrasileiro
Copy link
Contributor Author

I tested it simulating the error and I think it's not working as expected since we won't have the missing SKUs on the error message. "message": "Search API did not return the following skus: ",

Logs from the main local variables: Screen Shot 2022-04-08 at 12 58 15

So I have a suggestion:

  1. Maps the skus object as a key/value object.
const skus = skuIds.map((skuId) => ({
      key: skuId,
      value: skuBySkuId[skuId],
    }))
  1. The missingSkus mapping the new key (sku).
const missingSkus = skus.filter((sku) => !sku.value).map((sku) => sku.key)
  1. Keeps the original if and return the skus values:
if (missingSkus.length > 0) {
//...
}

return skus.map((sku) => sku.value)

logs after changes: Screen Shot 2022-04-08 at 13 10 48

error message: "message": "Search API did not return the following skus: 1010",

We can pair programming to discuss more :)

Your change doesn't fix the problem, fix the error message. Yeah, I can fix the error message too. Thank you

@igorbrasileiro
Copy link
Contributor Author

@eduardoformiga do you still think this change is necessary since now we're not using the checkout simulation?

@eduardoformiga
Copy link
Member

@eduardoformiga do you still think this change is necessary since now we're not using the checkout simulation?

I think we are using the skuLoader in other places than the checkout simulation. Like in the product Query resolver, and the validateCart (image below). So it would be great to have the error message logging as expected, with the correct skus. But we can address it afterward as well. What do you think?

Screen Shot 2022-05-23 at 17 35 26

@emersonlaurentino emersonlaurentino deleted the fix/sku-loader branch May 30, 2022 21:52
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.

4 participants