When being rejected
If, despite your best efforts, you have received a rejection, it may be worthwhile - after the initial emotions have subsided - to ask the company why it did not work out. Try to receive the feedback as constructive criticism, and a reference point for your own further development. Also, be sure to write down the feedback, even though you may be frustrated at first. Reflect on whether and how you could use this information to prepare for future application procedures. In this context, also consider whether and what further training or education would make sense to increase your chances of success.
In addition to the feedback from the company, you should also take time to reflect as objectively as possible on the situations before, during or immediately after the interview or assessment that could have led to the rejection. Do you notice any mistakes you may have made? Then write them down and think about what led to these mistakes or how you would like to go about making improvements.