Skip to content

The open alternative to Salesforce, designed for AI.

Stop throwing for event stream does not exists (#20008)

Thomas Trompetted887fdc53270
diff --git a/packages/twenty-server/src/engine/subscriptions/event-stream.resolver.ts b/packages/twenty-server/src/engine/subscriptions/event-stream.resolver.ts
index 3bddb18cef7..481bd1e9539 100644
--- a/packages/twenty-server/src/engine/subscriptions/event-stream.resolver.ts
+++ b/packages/twenty-server/src/engine/subscriptions/event-stream.resolver.ts
@@ -64,16 +64,31 @@ export class EventStreamResolver {
) {
const eventStreamChannelId = eventStreamIdToChannelId(eventStreamId);
- const streamData = await this.eventStreamService.getStreamData(
+ const existingStreamData = await this.eventStreamService.getStreamData(
workspace.id,
eventStreamChannelId,
);
- if (isDefined(streamData)) {
- throw new EventStreamException(
- 'Event stream already exists',
- EventStreamExceptionCode.EVENT_STREAM_ALREADY_EXISTS,
- );
+ if (isDefined(existingStreamData)) {
+ const isAuthorized = await this.eventStreamService.isAuthorized({
+ streamData: existingStreamData,
+ authContext: {
+ userWorkspaceId,
+ apiKeyId: apiKey?.id,
+ },
+ });
+
+ if (!isAuthorized) {
+ throw new EventStreamException(
+ 'Event stream already exists',
+ EventStreamExceptionCode.EVENT_STREAM_ALREADY_EXISTS,
+ );
+ }
+
+ await this.eventStreamService.destroyEventStream({
+ workspaceId: workspace.id,
+ eventStreamChannelId,
+ });
}
await this.eventStreamService.createEventStream({