angry when baby cries

My DD is four months old. I'm at SAHM. I nurse her and she has an allergy to the protein in cows milk so I've had to cut out all dairy from my diet. If I unknowingly eat something that contains the smallest amount of dairy, she will scream and cry at night with her belly hurting. I truly enjoy being a mother and love her with everything in me. However, when she starts to cry like this and it's difficult to console her or it's in the middle of the night, I get so tense. My heart starts racing, I have this wave of rage wash over me. It is controllable, I know I would never harm her. Shamefully I will admit that in the moment I will scream at her. When she is finally calm I feel so incredibly guilty! I know she can't help it and I know my behavior isn't helping nor appropriate. I feel so embarrassed and ashamed of myself. I apologize to her, not that she understands but I want to get myself together so that this quits happening and also doesn't happen with my next baby. Any tips for staying calm and out of the red in these difficult moments?