Learn to encourage a culture of compassion, specifically self-compassion and self-forgiveness. Instead of beating yourself up about your mistakes, try to build the muscles to help you be resilient. If you feed your resilience effectively, then you will be happy irrespective of what life brings you.
You need to put on your protective shield. You should not walk onto the battlefield of life without doing your training and shielding.