Jump to content

Handle Wire404Exception thrown from ready.php


Recommended Posts

Good day everybody!

I am trying to use wire404() in ready.php. The function throws an exception, but it is not caught with PW the standard way. The 404 page is not displayed  but an error page is displayed instead. I guess that the hook to catch the exception is defined later in the request handling lifecycle.

  1. Am I right or is it something else?
  2. Can I somehow make PW catch this exception in ready.php? (in fact it doesn't work in template prepend file like _init.php either, but I need it earlier)
  3. If 2 cannot be achieved, what is a proper way to work this around and return a 404 page with 404 http code manually? 

Thanks in advance!

P.S. The 4th of April was not so long ago so this might relate)))

Link to comment
Share on other sites

  • Ivan Gretsky changed the title to Handle Wire404Exception thrown from ready.php

I'm not sure what the technical reason is for the 404 not being handled from ready.php, but as a workaround you could set a custom property on the $page object to indicate that a 404 should be thrown and then throw the 404 later, e.g. from a template file or from _main.php.

// Your conditional in ready.php
if($foo === 'bar') $page->throw404 = true;

 

// In template file or _main.php
if($page->throw404) wire404();
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...