There are laws against harassment in many jurisdictions. The definitions of harassment in these laws, like all laws addressing relationship violence, tend to be anchored in the concept of assault and physical harm. But as explained elsewhere on this site, the real basic character of domestic violence is in depriving survivors of the possibility of acting on their behalves, and the definition below reflects that part as well.
Harassment is 1) a pattern of unwanted contact that robs the survivor of privacy, and the ability to relax and feel safe, or 2) a pattern of interfering in the survivors relationships with others. In harassment, no individual piece is a crime or assault. For instance, if John feels cheated, suing Mary once is not harassment even if his case is objectively weak. Calling Mary more than once in an evening is not violation of Mary's rights if John is worried about her. Coming up to Mary once in the street and asking a pointed question is not a crime if he feels Mary has been avoiding giving him an answer that he has a right to. Going to her address to check on her may be justified if John is worried about her welfare. 'Warning' her friend or a co-worker about her may be justified if he thinks she poses an emotional danger. Because all these matters are subjective, he gets some leeway.
Of course, anyone familiar with abuse understands that in primary aggression, the example motivations given above are not at all what is driving the contact. But as a construct, these types of behaviors, even if edgy, are allowed in a society, when rare, even if they are annoying. Any one of these types of unwanted contact of course raise mild alarm in the target. When there is a pattern of several rapid acts like this, it is understood that the pattern then becomes a violation of the survivors rights because a threshold of on-going alarm has been crossed. The survivor has been intimidated and options taken away.
This is why no-contact, anti-harassment, and protection orders are absolute about contact, even third-party contact, to make justification irrelevant. Even with such an order in place, it is possible for a primary aggressor to harass via the court system. That is why special DV courts and DV family courts are helpful.