Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Skip group change email when the group is missing

Kiran K0bf5d044bb98
diff --git a/apps/web/lib/api/partners/notify-partner-group-change.ts b/apps/web/lib/api/partners/notify-partner-group-change.ts
index ad507e87fa..a381e62d45 100644
--- a/apps/web/lib/api/partners/notify-partner-group-change.ts
+++ b/apps/web/lib/api/partners/notify-partner-group-change.ts
@@ -1,3 +1,4 @@
+import { DubApiError } from "@/lib/api/errors";
import { queueBatchEmail } from "@/lib/email/queue-batch-email";
import type PartnerGroupChanged from "@dub/email/templates/partner-group-changed";
import { getGroupRewardsAndBounties } from "./get-group-rewards-and-bounties";
@@ -21,23 +22,34 @@ export async function notifyPartnerGroupChange({
return;
}
- const [
- {
- rewards,
- bounties,
- group: { program },
- },
- partnerUsers,
- ] = await Promise.all([
- getGroupRewardsAndBounties({
+ let groupRewards: Awaited<ReturnType<typeof getGroupRewardsAndBounties>>;
+
+ try {
+ groupRewards = await getGroupRewardsAndBounties({
programId,
groupId,
- }),
+ });
+ } catch (error) {
+ if (
+ error instanceof DubApiError &&
+ (error.code === "not_found" || error.code === "forbidden")
+ ) {
+ console.info(`Group ${groupId} not found. Skipping...`);
+ return;
+ }
+
+ throw error;
+ }
+
+ const {
+ rewards,
+ bounties,
+ group: { program },
+ } = groupRewards;
- getPartnerUsers({
- partnerIds,
- }),
- ]);
+ const partnerUsers = await getPartnerUsers({
+ partnerIds,
+ });
await queueBatchEmail<typeof PartnerGroupChanged>(
partnerUsers.map(({ partner, user }) => ({