Hide
on 19/4/07

I wrote recently about how to have your site(s) email you whenever a problem occurs. Trouble is "problem" turns out to be a rather broad scope. If you have a missing file or fundamental problem of some kind, you would want to know so you can fix it; if there was a dead link on your site, you would also want to fix it; if someone just mistypes the url (or follows a link from an outdated source) you may not want an email each time this happens. At some point in between reading the comment from (the esteemed) Dr Tarique Sani and deleting the 4000+ emails I received from my site in the meantime, I came to realize that there has to be a better way to record what errors are occurring on a site. So that's what I'll be talking about today ;).

Limiting Scope

When I reviewed the emails that my site has sent me in the past week, there were many duplicates. The cause for most of the generated errors were either links to old pages which don't exist anymore or have been moved, or broken links on the site. When I switched host I also changed from (case insensitive) php4 to (case sensitive) php5, this caused many links to stop working. I was glad to know of how and why these errors were occurring, but once would have been enough ;). Of the types of errors that can occur, there is one case in which I want an email every time it happens - if there is a missing connection (which should be rare to never). So changes have been made to check for and only email in this circumstance, for the rest of the time...

on 31/3/07

Have you ever wondered what the reason for that 404 error is when you set debug to 0, or when you move your site onto your live server? How many visitors/clients are confronted by a 404 when they should be looking at the fruits of your work? Cake allows you to modify what happens in the case of an error, and the purpose of this post is to show how to make your site mail you (or the website admin if it's not you) or take whatever other action you might want whenever a 404 is generated.

I'll keep it short and sweet today :). Create the file app/app_error.php app/error.php with the contents below:

on 6/9/06

One of the changes I made to my site recently, was to override the App Error Function to keep track of how things are going wrong. I did this by simply logging all the information available and redirecting the user to a safe page (the home page).

I've found this to be very useful in general, especially for debugging what was going wrong with multiple inter-plugin requestAction calls on the same page (2 pastes on the same blog didn't work without some tweaking, I might say something about that soon).