I ran into the exact same problem a couple weeks ago. My bike sometimes wouldn't even turn on, and sometimes would turn off mid-ride, especially after bumps. Just like yours, my fan, lights, etc kept working regardless.
The culprit turned out to be a loose connection to the ON/OFF switch for...