Recently I've been having severe anxiety attacks, linked with depression. How do I cope with it when it happens?

Depends on diagnosis. There are many types of depression and anxiety, some short lived. Adjustment disorders and single incident ptsd can be treated quickly.. Recurrent major depression, bipolar disorders, and panic take longer. Mindfulness based cognitive therapy and energy psychology are effective approaches, generally combined with medication. Energy tapping is a self help technique you might explore.
Develop a plan. Get a team, a counselor, and psychiatrist, a good friend or two, a spouse, a partner, and fiance. See the counselor find out what your stressors are. Talk about behavioral coping skills to use when paniv sets in. Have a friend or two on call if it gets bad. Talk to the doctor about anxiety and depression meds to reduce your symptoms overall. And maybe some meds as needed when panic starts.