mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Improved error logging for webhook handling
no-issue
This commit is contained in:
parent
310972f73c
commit
5a17327a93
2 changed files with 12 additions and 4 deletions
|
@ -192,9 +192,15 @@ module.exports = function MembersApi({
|
|||
});
|
||||
|
||||
middleware.handleStripeWebhook.use(ensureStripe, body.raw({type: 'application/json'}), async function (req, res) {
|
||||
let event;
|
||||
try {
|
||||
event = await stripe.parseWebhook(req.body, req.headers['stripe-signature']);
|
||||
} catch (err) {
|
||||
common.logging.error(err);
|
||||
res.writeHead(401);
|
||||
return res.end();
|
||||
}
|
||||
try {
|
||||
const event = await stripe.parseWebhook(req.body, req.headers['stripe-signature']);
|
||||
|
||||
if (event.type === 'customer.subscription.deleted') {
|
||||
await stripe.handleCustomerSubscriptionDeletedWebhook(event.data.object);
|
||||
}
|
||||
|
@ -226,7 +232,7 @@ module.exports = function MembersApi({
|
|||
res.writeHead(200);
|
||||
res.end();
|
||||
} catch (err) {
|
||||
common.logging.error(err);
|
||||
common.logging.error(`Error handling webhook ${event.type}`, err);
|
||||
res.writeHead(400);
|
||||
res.end();
|
||||
}
|
||||
|
|
|
@ -80,7 +80,9 @@ module.exports = class StripePaymentProcessor {
|
|||
}
|
||||
|
||||
async parseWebhook(body, signature) {
|
||||
return this._stripe.webhooks.constructEvent(body, signature, this._webhookSecret);
|
||||
const event = await this._stripe.webhooks.constructEvent(body, signature, this._webhookSecret);
|
||||
debug(`Parsed webhook event: ${event.type}`);
|
||||
return event;
|
||||
}
|
||||
|
||||
async createCheckoutSession(member, planName, options) {
|
||||
|
|
Loading…
Add table
Reference in a new issue