Skip to content

Commit 9f59d15

Browse files
committed
refactor: improve error handling in notification persistence and publishing
- Enhanced the `persistNotificationFn` to include error handling for both notification row insertion and message publishing. - Updated the insert and publish operations to return success status and messages, improving clarity and debugging capabilities.
1 parent 802dbb3 commit 9f59d15

1 file changed

Lines changed: 27 additions & 7 deletions

File tree

src/lib/inngest.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,17 +190,37 @@ export const persistNotificationFn = inngest.createFunction(
190190
created_at: new Date(),
191191
};
192192

193-
// Durable step: retries must not insert duplicate rows when a later line fails.
194193
await step.run("insert-notification-row", async () => {
195-
await persistenceRepository.notification.insert([row]);
194+
try {
195+
const result = await persistenceRepository.notification.insert([row]);
196+
return {
197+
insertedRow: result?.rows?.[0],
198+
};
199+
} catch (err) {
200+
return {
201+
insertedRow: null,
202+
message: "Failed to insert notification row",
203+
};
204+
}
196205
});
197206

198207
await step.run("publish-notification-realtime", async () => {
199-
return await publishMessage(
200-
`private-user.${data.recipient_id}`,
201-
REALTIME_PUSHER_EVENTS.NOTIFICATION_NEW,
202-
{ scope: "notifications" },
203-
);
208+
try {
209+
await publishMessage(
210+
`private-user.${data.recipient_id}`,
211+
REALTIME_PUSHER_EVENTS.NOTIFICATION_NEW,
212+
{ scope: "notifications" },
213+
);
214+
return {
215+
published: true,
216+
message: "Notification published successfully",
217+
};
218+
} catch (err) {
219+
return {
220+
published: false,
221+
message: "Failed to publish notification",
222+
};
223+
}
204224
});
205225

206226
return { success: true };

0 commit comments

Comments
 (0)