Baby and Dog

Okay so my son is 10 Months Old and I’ve had my dog for 7 years (since I was 12) his name is Diego. He’s a chihuahua, so not a stereotypical “dangerous” dog. And he’s not the annoying, yappy, ankle-biter kind. He’s usually really chill, kind of lazy now since he’s old. And he’s ALWAYS been around kids because I have a lot of younger cousins, he’s always been gentle with babies. This isn’t the first time he’s met my son, as well. But today my son was petting him (open palm, he wasn’t gripping anything) and Diego turned to him quickly and growled and nipped at him! He didn’t bite my son but he did scare him. I punished the dog and put him in his crate for a little bit (crate big enough for a medium-large dog, he had food and water inside and was only locked up for about an hour). I’m not sure what to do! I don’t want to get rid of my dog but I will if I have to 😭