First, look over all wires and plugs, looking for abraded areas, any zipties that may be too tight on them, causing a break. Then I would pull all plugs and look for corrosion, clean, put a touch of grease on the plastic for sealing, and plug it back in.
If that doesn't reveal anything, take it to a shop with the diagnostics box.
Internal wires or external? if internal, there are 4 more plugs inside that rely on heavy duty heat shrink for sealing. I've seen some people leave theirs off, with consequences.
Any crashes? One RD stopped signaling to the FD of its position, so the FD no longer trimmed, after a pretty big crash. so if you know someone w another RD, that's something to check. If you know someone with another di2 bike, you could easily plug your stuff into his to locate the culprit.