@scayle/storefront-core
Version:
Collection of essential utilities to work with the Storefront API
24 lines (23 loc) • 566 B
JavaScript
import { FetchError } from "@scayle/storefront-api";
export function mapSAPIFetchErrorToResponse(func) {
return async (...args) => {
try {
return await func(...args);
} catch (e) {
if (e instanceof FetchError) {
const response = e.response;
return Response.json(
{
statusCode: response.status,
statusMessage: response.statusText
},
{
status: response.status,
statusText: response.statusText
}
);
}
throw e;
}
};
}