I'm all for being aware and considering underlying needs/reasons (such as need for connection, hunger, fatigue, anxiety, etc.), but you know sometimes these things just come down to personality and maturity. Sometimes it's just a phase you get through, doing the best you can. You can be connecting and doing everything "right" and still go through these tough times. That you're going through this is not necessarily an indication that you're missing anything or doing anything wrong.
Some phases of development are harder to navigate than others. It will pass. Remember, he's only 4 so his skills are limited (and often it's skills (maturity) that are the underlying thing). If he doesn't want to do something, he's not always going to communicate that to you gracefully. He isn't always able to accurately identify or tell you how he feels. His impulse control is still limited. Flexibility may be difficult for him. He may have trouble shifting from what he's doing to what you want him to do (this is a real and important cognitive skill). Etc., etc. He will mature and these skills will improve. In the meantime, don't beat yourself up and blame yourself. Take a breather when you need to, be as mindful as you can be, respond as best you can, and help him learn those skills. You'll both get through this, and you'll both learn to handle these situations more effectively.
It took me a long time to realize that I can't blame myself for everything. There are two people in a parent-child relationship, and I only have control over myself. My child is an active participant in this too. We work together. I can do my best and always learn to do better, and certainly as the adult have responsibilities in this relationship that my child does not, but not every ongoing difficult behavior is a sign of my failing as a mother. And you know, kids are resilient. My oldest is about to turn 11, and we have been through the ringer. She's been a very, very challenging kid to parent, and I have yelled way too much over the years. And now? She's blossoming in this amazing way, and she's okay. She's more than okay. She's a strong, confident, creative, and compassionate girl. Maturity has given her better and better skills over the years (as more experience parenting has given me better skills with which to parent). And our relationship is good--not perfect, but good in a warts-and-all human way. We are enjoying each other now in new, fun ways that bring us closer. I don't know what the next several years will bring, but now I trust that she (and we) will be okay in the long run, even though I am only a human mother who makes mistakes.