From a15933596c9a496f96f319c66f9b0a59d5f89520 Mon Sep 17 00:00:00 2001 From: Christomatt Date: Mon, 26 Jan 2026 11:12:32 +0100 Subject: [PATCH] fix(swarm): Add error handling for notification creation in interactions - Wrap notification creation in try-catch blocks for follow interactions - Wrap notification creation in try-catch blocks for like interactions - Wrap notification creation in try-catch blocks for repost interactions - Add console logging for successful notification creation with interaction details - Add error logging for failed notification creation to aid in debugging - Prevent interaction failures from cascading due to notification errors --- src/app/api/swarm/interactions/follow/route.ts | 15 ++++++++++----- src/app/api/swarm/interactions/like/route.ts | 17 +++++++++++------ src/app/api/swarm/interactions/repost/route.ts | 17 +++++++++++------ 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/src/app/api/swarm/interactions/follow/route.ts b/src/app/api/swarm/interactions/follow/route.ts index efb746f..5b228b1 100644 --- a/src/app/api/swarm/interactions/follow/route.ts +++ b/src/app/api/swarm/interactions/follow/route.ts @@ -104,11 +104,16 @@ export async function POST(request: NextRequest) { } // Create notification - await db.insert(notifications).values({ - userId: targetUser.id, - actorId: remoteUser.id, - type: 'follow', - }); + try { + await db.insert(notifications).values({ + userId: targetUser.id, + actorId: remoteUser.id, + type: 'follow', + }); + console.log(`[Swarm] Created follow notification for @${data.targetHandle} from ${remoteHandle}`); + } catch (notifError) { + console.error(`[Swarm] Failed to create notification:`, notifError); + } // Also notify bot owner if this is a bot being followed const { notifyBotOwnerForFollow } = await import('@/lib/notifications/botOwnerNotify'); diff --git a/src/app/api/swarm/interactions/like/route.ts b/src/app/api/swarm/interactions/like/route.ts index ed2d317..bc6d5f3 100644 --- a/src/app/api/swarm/interactions/like/route.ts +++ b/src/app/api/swarm/interactions/like/route.ts @@ -77,12 +77,17 @@ export async function POST(request: NextRequest) { } // Create notification - await db.insert(notifications).values({ - userId: post.userId, - actorId: remoteUser.id, - postId: data.postId, - type: 'like', - }); + try { + await db.insert(notifications).values({ + userId: post.userId, + actorId: remoteUser.id, + postId: data.postId, + type: 'like', + }); + console.log(`[Swarm] Created like notification for post ${data.postId} from ${remoteHandle}`); + } catch (notifError) { + console.error(`[Swarm] Failed to create like notification:`, notifError); + } // Also notify bot owner if this is a bot's post const { notifyBotOwnerForPost } = await import('@/lib/notifications/botOwnerNotify'); diff --git a/src/app/api/swarm/interactions/repost/route.ts b/src/app/api/swarm/interactions/repost/route.ts index be330f5..8663c8c 100644 --- a/src/app/api/swarm/interactions/repost/route.ts +++ b/src/app/api/swarm/interactions/repost/route.ts @@ -72,12 +72,17 @@ export async function POST(request: NextRequest) { } // Create notification - await db.insert(notifications).values({ - userId: post.userId, - actorId: remoteUser.id, - postId: data.postId, - type: 'repost', - }); + try { + await db.insert(notifications).values({ + userId: post.userId, + actorId: remoteUser.id, + postId: data.postId, + type: 'repost', + }); + console.log(`[Swarm] Created repost notification for post ${data.postId} from ${remoteHandle}`); + } catch (notifError) { + console.error(`[Swarm] Failed to create repost notification:`, notifError); + } // Also notify bot owner if this is a bot's post const { notifyBotOwnerForPost } = await import('@/lib/notifications/botOwnerNotify');