Deleting an element of the diagram on create.PostExecute

Hello,
I am trying to delete an element if it goes in my else statement, but all that the this.modeling.removeElements is doing is deleting the line that connects the actual element.
Anyone have any idea what am I doing wrong?
Any help would be appreciated

eventBus.on('commandStack.connection.create.postExecute', (event: any) => {
        console.log('PostExecute:', event);

        const connection = event.context.connection;
        const sourceElement = connection.source.type;
        const targetElement = connection.target.type;
        
        const targetShape = connection.target;
        if(targetElement === 'bpmn:Task'){
          if (sourceElement === 'bpmn:ExclusiveGateway'){
            console.log('GOOD');
          } else {
            console.log('BAD');
            alert("Greska");

            this.modeling.removeElements([targetShape]);
            console.log('delete good :::connection',);
            throw new Error("TargetGateway error")
          }
        }
      });

It seems like you want to disallow creating connections in certain cases. You can use custom rules to achieve that so you don’t have to bother with having to delete a connection that shouldn’t have been created in the first place.