Hey all,  TW: suicidal thoughts

so as the title suggests today I got a bad mark on a test and it destroyed me. I immediately started insulting myself mentally, assuming i would fail all my other classes too, and pretty much downspiraling. It was pretty nasty and I even had thoughts of how im such a failure and if i fail my other classes i'm going to kill myself. I thought this seriously. Immediately after I thought that I scared myself back to reality, I managed to talk to my teacher and discuss how I can improve my grade so the mark has less of an effect. While im disappointed in my reaction, i'm a bit proud that I got myself to take a step back and handle it.

Has anyone else here had struggles with removing your self worth from grades? How do/did you do it? Any recommendations on keeping school from smashing your mental stability?