Skip to content

[FEATURE] Expose rawResponse flag for commerce-sdk-react hooks #2807

@joeluong-sfcc

Description

@joeluong-sfcc

Is your feature request related to a problem? Please describe.
In the commerce-sdk-isomorphic there is a rawResponse flag available that you can pass into endpoint function calls to retrieve the full response object as the return type instead of the parsed data.

In the commerce-sdk-react, this is flag is not available on most hooks. The only react hook that exposes rawResponse is the custom API endpoint hook.

The reason why this is useful is because when throwOnBadResponse is enabled in client config (which commerce-sdk-react does), any non 2xx or 304 response is treated as an error. For certain operations, a 301 will be provided and as a result, an error will be triggered. Example:

try {

    const updateCustomerAddress = useShopperCustomersMutation('updateCustomerAddress')
    const resData = await updateCustomerAddress.mutateAsync({
        body: {
            addressId: trimAddress.addressId,
            address1: trimAddress.address1,
        },
        parameters: {
            customerId: customer.customerId,
            addressName: updatedAddressID // Updating addressID returns 301 response
        }
    })

    // continue doing stuff
} catch (error) {
    // error handling gets triggered on 301
}

Having the rawResponse flag available will allow customers to handle cases like these where they would like to continue the path of execution in the try block instead of getting an error thrown.

This is also useful for any customer who wants full details of the response object and not just the data provided by the API.

Describe the solution you'd like
rawResponse flag is exposed for react hooks

Describe alternatives you've considered

Alternatively, we can update the commerce-sdk-isomorphic to also include 301 as a valid HTTP status code for throwOnBadResponse

Additional context
Add any other context or screenshots about the feature request here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions