feat: handle http exceptions (#456)

This commit is contained in:
Ahmed Bouhuolia
2024-05-22 19:30:41 +02:00
committed by GitHub
parent 1227111fae
commit 0836fe14e0
14 changed files with 102 additions and 66 deletions

View File

@@ -10,6 +10,7 @@ import {
} from './utils';
import { Plan } from '@/system/models';
import { Subscription } from './Subscription';
import { isEmpty } from 'lodash';
@Service()
export class LemonSqueezyWebhooks {
@@ -32,6 +33,9 @@ export class LemonSqueezyWebhooks {
if (!config.lemonSqueezy.webhookSecret) {
throw new Error('Lemon Squeezy Webhook Secret not set in .env');
}
if (!signature) {
throw new Error('Request signature is required.');
}
const secret = config.lemonSqueezy.webhookSecret;
const hmacSignature = createHmacSignature(secret, rawData);
@@ -49,7 +53,7 @@ export class LemonSqueezyWebhooks {
/**
* This action will process a webhook event in the database.
* @param {unknown} eventBody -
* @param {unknown} eventBody -
* @returns {Promise<void>}
*/
private async processWebhookEvent(eventBody): Promise<void> {
@@ -96,7 +100,7 @@ export class LemonSqueezyWebhooks {
if (webhookEvent === 'subscription_created') {
await this.subscriptionService.newSubscribtion(
tenantId,
'early-adaptor',
'early-adaptor'
);
}
}