hyva-themes / magento2-react-checkout

Highly Customizable Checkout for Magento 2, Built with React.
BSD 3-Clause "New" or "Revised" License
178 stars 53 forks source link

The current sendRequest does not handle returned errors if data is present #287

Closed jladmore closed 1 year ago

jladmore commented 2 years ago

The aggregateQuery can return data and errors. The case I found was where a logged in user does a mergeCart and the requested quantity is no longer available. So the returned cart has a data object and an error object.

The user needs to see this error otherwise the cart goes blank and there is no explanation as to what happened.

The other issue is that the cart is not parsed correctly, but I will leave this for the moment. Its more important that the error is displayed.

data and errors

rajeev-k-tomy commented 2 years ago

It is intended in this way actually. If the cart contains a valid information, then we don't want to break the application, but just want to continue. There can be many occasions in which you will get errors and still the cart information is valid. Most of the times, errors on the list may be some irrelevant such as schema invalid warning messages.

So you can either tackle this in the actual api method instead of dealing this inside sendRequest method. If the error is relevant for you to break the application, then check the error in your api method and breake it by throwing error as you have done here.

Else, make sure the response contains cart: null so that it will be kill the checkout by throwing the error as you can see sendRequest is already handling it there.