Debugging fetch in a consumer
Yes, I'm
The last log I see is the
awaitawaiting the fetchfetch and I also put inside a try/catchtry/catch, but no error is logged. The last log I see is the
API URLAPI URL log, and then the code skips everything below the logtry {
console.log('API URL :', `${env.STRAPI_API_URL}/c-orders`);
const connection = await fetch(`${env.STRAPI_API_URL}/c-orders`, {
headers: {
Authorization: `Bearer ${env.STRAPI_API_KEY}`,
'Content-Type': 'application/json',
},
method: 'POST',
body: JSON.stringify({
data: {
planId,
date: new Date(),
deliveryDate: new Date(deliveryDate * 1000),
status: 1,
details,
grossPrice: totalPrice,
finalPrice: totalPrice,
subscriptionId: subscription ? strapiSubscriptionId : null,
userId,
paymentId: paymentIntent,
paymentStatus: subscription ? 'processing' : 'success',
orderInfo: [],
stripeInvoiceId: invoice,
},
}),
});
console.log('connection :', connection);
const data = await connection.json();
console.log('data :', JSON.stringify(data, null, 2));
if (connection.status !== 200) wasOrderCreated = false;
wasOrderCreated = true;
} catch (err) {
console.log('err :', err);
return false;
}try {
console.log('API URL :', `${env.STRAPI_API_URL}/c-orders`);
const connection = await fetch(`${env.STRAPI_API_URL}/c-orders`, {
headers: {
Authorization: `Bearer ${env.STRAPI_API_KEY}`,
'Content-Type': 'application/json',
},
method: 'POST',
body: JSON.stringify({
data: {
planId,
date: new Date(),
deliveryDate: new Date(deliveryDate * 1000),
status: 1,
details,
grossPrice: totalPrice,
finalPrice: totalPrice,
subscriptionId: subscription ? strapiSubscriptionId : null,
userId,
paymentId: paymentIntent,
paymentStatus: subscription ? 'processing' : 'success',
orderInfo: [],
stripeInvoiceId: invoice,
},
}),
});
console.log('connection :', connection);
const data = await connection.json();
console.log('data :', JSON.stringify(data, null, 2));
if (connection.status !== 200) wasOrderCreated = false;
wasOrderCreated = true;
} catch (err) {
console.log('err :', err);
return false;
}
