Was it right to default Medvedev for hitting spectator with ball?

Wait 5 sec.

Daniil Medvedev was defaulted for hitting a spectator with the ball during his semi-final with Novak Djokovic at the China Open, but was it the correct decision or should he have been able to continue playing?