Log error

This commit is contained in:
goncy
2021-09-29 11:11:16 -03:00
parent 4b710bf850
commit efa1521bb9
2 changed files with 19 additions and 34 deletions

View File

@@ -13,39 +13,24 @@ const getCheckout: CheckoutEndpoint['handlers']['getCheckout'] = async ({
}) })
} }
try { // Register credit card
// Register credit card const payments = await restFetch(
const payments = await restFetch( 'GET',
'GET', `/orders/Outgoing/${cartId}/payments`
`/orders/Outgoing/${cartId}/payments` ).then((response: { Items: unknown[] }) => response.Items)
).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

View File

@@ -95,12 +95,12 @@ export async function fetchData<T>(
} }
// Get the body of it // Get the body of it
const error = await dataResponse.json() const error = await dataResponse.textConverted()
// And return an error // And return an error
throw new FetcherError({ throw new FetcherError({
errors: [{ message: error.error_description.Code }], errors: [{ message: error || dataResponse.statusText }],
status: error.error_description.HttpStatus, status: dataResponse.status,
}) })
} }