Perceived danger is exactly how self-defense law is written. The innocent defender must have an objectively and subjectively reasonable belief that they are facing an imminent threat, that is, they are in jeopardy, from a person with the ability and opportunity to, in the case of deadly force, cause them death or grievous bodily harm.

There is no legal or moral requirement to first actually be harmed, or wait to try to interrupt a blow already struck, before using force in self-defense. Once force is justified, given that most events are over in a few seconds, what constitutes excessive force is something for the jury. There's no bright line "'n' is too many shots," for example.

Andrew Branca's "Law of Self-Defense" is probably the premier book on the subject for hose who are interested in actually learning about the subject.

Dogs or other animals will be a bit different given agency, but the principles are the same. You don't have to let something bite you before trying to stop it.