mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 20:26:49 +00:00
Log checkout error
This commit is contained in:
@@ -2,7 +2,7 @@ import type { CheckoutEndpoint } from '.'
|
|||||||
|
|
||||||
const getCheckout: CheckoutEndpoint['handlers']['getCheckout'] = async ({
|
const getCheckout: CheckoutEndpoint['handlers']['getCheckout'] = async ({
|
||||||
res,
|
res,
|
||||||
body: {cartId},
|
body: { cartId },
|
||||||
config: { restFetch },
|
config: { restFetch },
|
||||||
}) => {
|
}) => {
|
||||||
// Return an error if no item is present
|
// Return an error if no item is present
|
||||||
@@ -13,23 +13,39 @@ const getCheckout: CheckoutEndpoint['handlers']['getCheckout'] = async ({
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register credit card
|
try {
|
||||||
const payments = await restFetch('GET', `/orders/Outgoing/${cartId}/payments`).then(
|
// Register credit card
|
||||||
(response: {Items: unknown[]}) => response.Items
|
const payments = await restFetch(
|
||||||
)
|
'GET',
|
||||||
|
`/orders/Outgoing/${cartId}/payments`
|
||||||
|
).then((response: { Items: unknown[] }) => response.Items)
|
||||||
|
|
||||||
const address = await restFetch('GET', `/orders/Outgoing/${cartId}`).then(
|
const address = await restFetch('GET', `/orders/Outgoing/${cartId}`).then(
|
||||||
(response: {ShippingAddressID: string}) => response.ShippingAddressID
|
(response: { ShippingAddressID: string }) => response.ShippingAddressID
|
||||||
)
|
)
|
||||||
|
|
||||||
// Return cart and errors
|
// Return cart and errors
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
data: {
|
data: {
|
||||||
hasPayment: payments.length > 0,
|
hasPayment: payments.length > 0,
|
||||||
hasShipping: Boolean(address)
|
hasShipping: Boolean(address),
|
||||||
},
|
},
|
||||||
errors: []
|
errors: [],
|
||||||
})
|
})
|
||||||
|
} catch (error: any) {
|
||||||
|
console.log(error, error.toString(), JSON.stringify(error))
|
||||||
|
|
||||||
|
// Return cart and errors
|
||||||
|
res.status(500).json({
|
||||||
|
data: null,
|
||||||
|
errors: [
|
||||||
|
{
|
||||||
|
message: error.message,
|
||||||
|
code: error.statusCode || error.code || error.status,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default getCheckout
|
export default getCheckout
|
||||||
|
Reference in New Issue
Block a user