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

I’d like to run some validation within the onReady function and if it fails I would like to throw an Http 404 so the user is redirected to the 404 page.

I have searched the forums and web but not been able to find how to do this in wix Corvid code. I’d appreciate any help or a pointer to where it may have already been answered (apologies if so)

thanks
David

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

Many thanks. I had a look at the wix-router and I suspect I’ll be using it later when I have more of the site developed. For this particular functionality though I needed a client-side redirect to a 404 Not Found page. I have a repeater page - when the page opens, if the data satisfies a certain condition it needs to redirect to 404. I thought there might be a corvid ‘throw 404 exception’ command but in the end I was able to solve it using a wixLocation .to redirect.
wixLocation.to(baseUrl + “Not Found” );

The NotFound page does not exist on the site so this redirect will force a 404 response.

Hi David,

Simply redirect them to a random URL that does not exist on your domain, and they’ll get the 404 error.

Super, thanks Ahmad. Yes that is what I did in the end - redirecting to a non existing page and letting the server handle the 404 redirect. I was hoping there was something a little more explicit on the client side … along the lines of ‘throw 404 exception’ but this solution is fine.

@davmay :wink: