“When you take the attack action”
The rules do not specify that you have to hit with your first attack in order to use your bonus action to attack again, so even if you miss on the first, you can get another swing in!