@scayle/storefront-core
Version:
Collection of essential utilities to work with the Storefront API
14 lines (13 loc) • 776 B
TypeScript
/**
* Wraps a Storefront API client function, catching Storefront API FetchErrors and converting them to a structured Response.
* This allows handling SAPI errors in a consistent way, returning a JSON response with status information.
*
* @template T The type of the Storefront API client function.
*
* @param func The Storefront API client function to wrap.
*
* @returns A wrapped function that returns a Promise resolving to either the original function's result or a JSON Response representing the error.
*
* @throws Re-throws any error that is not an instance of StorefrontAPI FetchError.
*/
export declare function mapSAPIFetchErrorToResponse<T extends (...args: any[]) => any>(func: T): (...args: Parameters<T>) => Promise<Awaited<ReturnType<T>> | Response>;