Some bites can hurt and some do not hurt at all.
Usually if you are reading and respecting body language and there's a clear path of 2 way communication going on, bites are very rare.
Unfortunately though, many birds learn that humans ignore or do not notice the subtle signs and so they learn to forgo all polite means of communication and go straight for the bite as that is the only effective way to get a desired response.
What you should do is contingent on why the bird resorted to biting you in the first place.
Prevention, like mentioned above, is the ideal route to take granted there is no immediate danger as we want to prevent the rehearsal of undesirable behaviors.
The punch line is that your response to the bite should not inadvertently reinforce the behavior.
There are countless examples so it's impossible to list them here but there are some common ones that seem to occur. If the bird bites you because it wants to be left alone, putting it away reinforces the behavior. If it bites you as it finds the loud animated reaction from you fun, you are reinforcing the behavior. If the bird is scared of something in the environment and it redirects a bite towards you or is attempting to resource guard you/something, where you move the bird and or the item or yourself, that can reinforce the behavior. If the bird doesn't want to go back into the cage, setting it down or tossing it into flight still free of the cage reinforces the behavior. If the bird is aroused and behaving in a hormonal manner and you do not redirect or move away because it bites, that reinforces the behavior.
Because there are so situations that can potentially illicit a bite, there isn't really one set thing to "do when you get bitten".
The only hard fast rule is to never hit the bird. I understand it can be a sudden reaction to yank away, swing/flinch but hitting will only, but not always, just suppress the behavior and will very likely damage your relationship.
Instead, you should try to address the issue from the bird's perspective so that you can identify what prompted the bite in the first place. That way, the core issue can resolved or managed. Biting is just a symptom/reaction so to speak of a negative state of mind.
I like to train and address the bird's perception versus their behavior. When you do this and change the bird's outlook on something for the better, the good and bad behaviors naturally take care of themselves.