Separate yourself from the problem
A problem is an event in your life. It is not who you are. Problems don't make your bad.
Keep it to the issue at hand
When you notice yourself leaving the current issue and overgeneralizing your mistakes to "everything", stop, take a breath, and remind yourself of the issue at hand.
Change to more accurate thoughts
Shift your thinking from what you did wrong to what you did-and do-right. What are your strengths? What are your skills?
To get unstuck, use your mistake in a positive way, to motivate you, help you shape your goals, and take action to accomplish those goals.