commerce/packages/swell/utils/handle-fetch-response.ts
2022-01-14 23:33:01 -05:00

20 lines
350 B
TypeScript

import { CommerceError } from '@vercel/commerce/utils/errors'
type SwellFetchResponse = {
error: {
message: string
code?: string
}
}
const handleFetchResponse = async (res: SwellFetchResponse) => {
if (res) {
if (res.error) {
throw new CommerceError(res.error)
}
return res
}
}
export default handleFetchResponse