magento2-react-checkout icon indicating copy to clipboard operation
magento2-react-checkout copied to clipboard

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

Open jladmore opened this issue 3 years ago • 1 comments

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

jladmore avatar Jun 03 '22 06:06 jladmore

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.

rajeev-k-tomy avatar Jun 16 '22 06:06 rajeev-k-tomy