When I first got my bike I'd be out in the middle of nowhere and suddenly the bike would just quit. What I discovered as many others have found is it was one of the sensors. In my case it was the brake sensor.
One of the two brake sensors I removed from the bike.
The white material I used to plug the hole where the brake sensor resides. All sensors are joined under the key ignition housing.
Sometimes it's the tilt sensor which shuts off the bike in the event you've fallen over. Or it could be the kickstand sensor which prevents the bike from running if the kickstand is down. There is also a sensor on the throttle located at the opposite end of the cable that attaches at the handlebar.
If it is not any of those sensors you could have something more serious like a bad BMS (Battery Management System) so check with the distributor where you bought your bike.