[Tip of the Week] Using your customErrorTemplate setting

ColdBox gives you several ways to deal with unhandled exceptions in your application such as the exceptionHandler event and the onException interception point to name a couple. With either of those approaches, you can redirect the request to a different event. If you don’t redirect or abort the request though, ColdBox will eventually display the contents of your error template.

By default the error template is /coldbox/system/includes/BugReport.cfm. This file has the familiar “Oops! Exception Encountered” header. While BugReport.cfm is chock-full of juicy error details (including the SQL of queries that errored), it isn’t the kind of information you want to be revealing to the general public.

This is where your customErrorTemplate setting from the ColdBox config file comes in. Set this to the path of the page you want your users to see when something goes wrong on the site.
settings.customErrorTemplate = “/includes/sorry.cfm”;

You’ll probably want to display a comforting message, a link to your webmaster’s E-mail address, or your customer service number. If you’re feeling cheeky, you could try an octocat, or fail whale. :slight_smile: Remember, your custom error template is NOT a view. It won’t be rendered inside your site layout and it won’t have access to variables a view normally gets, but it will have an exceptionBean object passed in. You can go digging for what you need with getController(), but 1be careful-- you don’t know what kind of state the framework is in. If you create an error on this page, it will bubble up to the onError method in your application.cfc.

More info here: http://wiki.coldbox.org/wiki/Recipes:Custom_Exception_Template.cfm

P.S. This is an excellent place to use environment overrides to use the default error page on your dev and staging server, but the pretty one on production. Just set the path to the pretty page in your main settings block, and override it with an empty string (which means use the default) in your lower environment overrides.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com