Yes you can safely eat undercooked cake and it will not harm you although it won't be as good as a fully cooked and baked cake.
Small cakes take between 15 to 30 minutes to bake and cook all the way and be ready to eat but some larger cakes can take as long as 40 minutes.
Once you remove the cake from the oven and allow it to cool down it cannot be baked any further as it will not rise anymore or bake anymore.
You can stick a toothpick or fork into the middle of the cake and if it comes out clean then the cake is done and ready to serve.
If not allow the cake to bake another 5 or 10 minutes and then check it again.
There's nothing in the undercooked cake that will make you sick as I used to eat cake mix off the spoon as a kid and still do and nothing bad has happened to me.