NEED OPINIONS!

So me and my boyfriend have been together for 3 years. At first we had a regular sex life up until last year. He’s a police officer and one day last year he went on a drug bust. Well when he opened up a baggie the contents of drugs/dust from drugs flew up in his face and he blacked out. Well come to find out months later it flared something up in his heart called tachycardia. So he’s been on anxiety meds and blood pressure meds since the incident. Before all this we had a falling out but eventually got back together several months later and I was there during all his doctors appointments and surgeries for his heart/tachycardia. So during this time we didn’t have sex for 6 months. And eventually we started back up again and had sex several times after(not using protection) (I know sounds complicated). Well once again the sex completely STOPPED again in December last year and we haven’t done anything since then. I have tried multiple times and basically just quit trying. So today I had to go run an errand, and I was gone for maybe 5 mins bc I had to drive back to the house for something. Well right when I walked in, I walked into his office to let him know I was there and I caught him jerking off! I was honestly shocked and really didn’t know what to say or how to react. But moments later I got really angry bc he doesn’t have sex with me but he can jerk his dick! He says he was trying to see if he could even get off bc of all the medicine he’s taking. But my whole reasoning is why couldn’t he see if he could with me? Why does he have to watch porn to see if he could get off? I almost felt like chop liver or maybe he wasn’t attracted to me anymore and he feels he’s better off using his hand. I mean I know guys watch porn and jerk off. But it kinda feels like a slap in the face when your bf doesn’t have sex with you for several months but you catch him doing that. He says the meds doesn’t give him the desire for sex anymore. I don’t know, maybe I overreacted. How would you feel? Please no mean comments!