How do I throw an error within $w.onReady?

Check the option Router wix-router api.
https://www.wix.com/velo/reference/wix-router/introduction