Skip to content

Commit

Permalink
fix: log errors upon running handlers (#4391)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrians5j authored Nov 20, 2024
1 parent bd038c0 commit 4e11136
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion packages/pubsub/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,23 @@ export const createTopic = <TEvent extends Event = Event>(topicName?: string): T
},
async publish(event: TEvent) {
for (const cb of subscribers) {
await cb(event);
try {
await cb(event);
} catch (e) {
console.error(
`An error occurred while publishing an event (topic: ${topicName}).`,
{
topicName: topicName,
error: {
message: e.message,
code: e.code,
data: e.data,
stack: e.stack
}
}
);
throw e;
}
}
}
};
Expand Down

0 comments on commit 4e11136

Please sign in to comment.