Search code examples
spartacus-storefront

How to access error details on API calls in Spartacus


I am trying to access error responses from API calls. But it looks like Spartacus STORES don't return this. What is the correct way to access the additional error data so I can handle it with custom actions in the component.

I have looked at the docs on this but this only returns the code and not the messages. I have also left a proposed fix in the repo


Solution

  • At the moment Spartacus doesn't have good error handling and we have it on our radar.

    In value fields for loader states, we only want to keep correct values and that's why we don't set by default error action payload as a value. However, you might want to achieve desired behavior by handling the error action in your reducer provided to LoaderReducer.

    value: reducer ? reducer(state.value, action) // you have this option. You can extract anything from this action and use it to set new state
     : undefined,