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.

Thank you for the suggestion. I did it as suggested. Just got a follow up question.
How to stop it from adding the element in question?
If I return false, it still gets added, and if I throw error it breaks the diagram…
Any suggestions?