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
This commit is contained in:
@@ -104,11 +104,16 @@ export async function POST(request: NextRequest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create notification
|
// Create notification
|
||||||
await db.insert(notifications).values({
|
try {
|
||||||
userId: targetUser.id,
|
await db.insert(notifications).values({
|
||||||
actorId: remoteUser.id,
|
userId: targetUser.id,
|
||||||
type: 'follow',
|
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
|
// Also notify bot owner if this is a bot being followed
|
||||||
const { notifyBotOwnerForFollow } = await import('@/lib/notifications/botOwnerNotify');
|
const { notifyBotOwnerForFollow } = await import('@/lib/notifications/botOwnerNotify');
|
||||||
|
|||||||
@@ -77,12 +77,17 @@ export async function POST(request: NextRequest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create notification
|
// Create notification
|
||||||
await db.insert(notifications).values({
|
try {
|
||||||
userId: post.userId,
|
await db.insert(notifications).values({
|
||||||
actorId: remoteUser.id,
|
userId: post.userId,
|
||||||
postId: data.postId,
|
actorId: remoteUser.id,
|
||||||
type: 'like',
|
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
|
// Also notify bot owner if this is a bot's post
|
||||||
const { notifyBotOwnerForPost } = await import('@/lib/notifications/botOwnerNotify');
|
const { notifyBotOwnerForPost } = await import('@/lib/notifications/botOwnerNotify');
|
||||||
|
|||||||
@@ -72,12 +72,17 @@ export async function POST(request: NextRequest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create notification
|
// Create notification
|
||||||
await db.insert(notifications).values({
|
try {
|
||||||
userId: post.userId,
|
await db.insert(notifications).values({
|
||||||
actorId: remoteUser.id,
|
userId: post.userId,
|
||||||
postId: data.postId,
|
actorId: remoteUser.id,
|
||||||
type: 'repost',
|
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
|
// Also notify bot owner if this is a bot's post
|
||||||
const { notifyBotOwnerForPost } = await import('@/lib/notifications/botOwnerNotify');
|
const { notifyBotOwnerForPost } = await import('@/lib/notifications/botOwnerNotify');
|
||||||
|
|||||||
Reference in New Issue
Block a user