Yesterday I was walking through a small Hamlet in southeast Slovenia and was confronted by two angry unleashed guard dogs, one large in size and one medium. So I held my trekking poles by the lower end and rested them on my shoulder to make myself look 50% taller, took out my bear spray, took off the safety catch, and aimed my bear spray squarely at the nose of the closest dog as I was walking past. However the owner came out and exclaimed "My dogs are no threat to you!" as a third dog (a Rottweiler) emerged from behind him. I felt some sympathy for the owner, being concerned for his dogs. So I pointed my bear spray downwards and tried to make a little small talk but didn't put the safety catch back on the bear spray because I still felt threatened. Was it wrong to draw my bear spray in this situation, or was it justified? On the one hand I believe dogs need to be kept on a leash, but on the other hand I am aware that angry unleashed dogs outside their owners' houses are going to become a more and more common situation as I walk southeastwards through the Balkans.
You describe a scary situation that was handled well by all involved, including the dogs. I think this is a good question because dog owners sometimes seem oblivious to the threat their dogs may pose or be perceived to pose to others.
I don't think there is anything you can do to absolutely guarantee to not get mauled AND not get into some kind of conflict with owners/bystanders. You can however minimize the risks by acting defensively towards the dogs you did in Slovenia. And to always keep communicating with people and ask them to be reasonable, should they take offense. As you also did in Slovenia.
Generally people in the Balkans consider it important to be reasonable and civil. An appeal to rules and laws might be less successful.
I do hope you get some answers from people who have experience hiking and biking in Bosnia. I never have personally, this is just general advice from my experience in (mostly) Croatia.
First, nothing you did seems, to me, like you were too aggressive. You protected yourself. In future incidents, you can apologize profusely to the owner, while still having protected yourself first. Doesn't really matter if you mean it or not, as long as it defuses the situation, after you've protected yourself. Maybe say that you have a dog phobia, poor you. Once the owner is there, as long as you don't get into a fight with him, attack risks should go down.
However, I will note one problem with your method. Dogs don't know about bear spray and it will not deter them until you use it, although your boosted confidence will likely make them more cautious. It can protect you if they attack, yes. But using bear spray is not trivially done, especially if the wind blows it back towards you, and it hurts even on skin exposure (personal experience, on leg).
I'd consider something like a walking staff (not a walking stick) as a big stick would be more recognizable and deterring to dogs. While bear spray would work better in an actual attack a hefty staff would not be negligible either.
Note that I don't use walking sticks, so switching to a staff would not bug me one bit.
In the initial stages, at a distance, pretending to reach down and pick up a rock is also surprisingly effective dissuading the merely curious in areas where dogs tend to roam around unsupervised.