Jump to content

Recommended Posts

Posted

I want to make a little module which logs all 404's and some more info like IP address, time, referrer, et cetera. Also it would be a nice addition if a developer generated 404 (i.e. using urlSegments and Throw Wire404Exception) could be included too. I think I can handle most stuff, but do have two questions:

1) How can I check if a Wire404Exception is being called?

2) When catching a Wire404Exception does that include all (both system and developer) generated 404's?

Thanks!

Posted

Yup - the 404 page is in the site tree as Willy says, so you could just change set a template for that page and do some code in there to keep it simple :)

Posted

Simple is good. :) I've thought about using the default 404 template, but a module seemed more logical. I use the 404 for markup purposes. Perhaps I have to rethink this.

  • 2 months later...
Posted

So there really isn’t a way to check if Wire404Exception is being called?

I have the problem that when

throw new Wire404Exception();

is being called, then the code of the 404 template is being included on the same page, but when another 404 occurs (e.g. the user typed a $input->urlSegment2 in the address bar, although only one segment is allowed) then only the 404 template is being called (that is without the inclusion of head.inc and foot.inc). Do you guys see what I mean? :)

So I’d need a method to check if Wire404Exception is explicitly called, so I know when and when not to include head.inc and foot.inc in the 404 template.

Posted

Solved it. I just throw the exception at the top of the page, before the head.inc of that page is included. Now I can call head.inc in the 404 template without worrying.

  • Like 1
Posted

You got it–a 404 should be thrown before you start outputting a page. If there is some other fatal error that occurs after you've started rendering your markup, it's better to throw a more generic WireException('your error message'). 

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
  • Recently Browsing   0 members

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