If your PS4 is going into rest mode while you are playing a game there may be a problem that isn't easily fixed at home; You might have to return it to Sony for repair.
There are a couple of things that you can try:
1. This doesn't sound like the issue since you are experiencing this while playing, but go into "Power Save Settings" and change it to "do not turn off" under "set time until PS4 turns off." I don't think this will work in your case, but it's easy and worth a try.
2. Try completely powering it down (no light at all on top of the console) then unplug it for 15 seconds. I've had a few issues with my PS4 ejecting discs, and this has helped about half of the time.
3. Last option before sending it for repair is to rebuild the database. Here are step-by-step instructions courtesy of Redditor Scrotal-Recall:
1. Turn the PlayStation 4 completely off.
2. Once the PlayStation 4 is off, press and hold the power button. Release it after you've heard two beeps: one when you initially press, and another 7 seconds later.
3. Connect the DualShock 4 controller with the provided USB cable and press the PS button on the controller.
4. Rebuild Database.