First things first - failures are bound to happen as humans are fallible. Personally, I'd try to not beat myself up over it to the point where I shoulder the entire guilt and burden of the consequences - even after the matter has been resolved.
I would say do what works best for you to cope with that failure (of course, no self-harming activities) for just that moment. Example: I like to watch a nice short comedy on Netflix just to get my mind off things. Once I have a clearer mind, I would reflect upon my experience and note down my reactions, the external factors involved etc. Some people might do journalling, some might want to talk it out with a though partner or mentor - the point is to take stock of whatever that has happened that led to such experience and use it as a learning moment, not as a wholesale definitive moment of what you are as a person (ie. a failure).