Posted in ColdFusion | Posted on 12-04-2006 | 2,040 views
A few days ago I promised I'd blog about the error templates I use. Obviously part of the template is set up to show the site's look and feel and present a generic "We are so sorry, blah blah blah" type message. Outside of that though here is typically what I do with the error itself.
2<cfdump var="#exception#" label="Exception">
3<cfdump var="#cgi#" label="cgi">
4<cfdump var="#form#" label="form">
5<cfdump var="#url#" label="url">
6</cfmail>
As you can see - I just take a massive dump in the email. Typically this is all I need. Sometimes though I need the session info so I just add a dump of that. I also bring up information on top of the dumps when I think it will be helpful. So for example, on RIAForge, I have both a main site and any number of project sites. To help me see a bit quicker, I can add this on top:
2URL: http://#cgi.server_name##cgi.script_name#?#cgi.query_string#<br />
I typically also make the URL hot to ensure I can click on it from my email program.
Another idea to consider is placing the exception.message value in the message subject. You may want to trim it at 500 characters or so to keep it readable in your mail program.
One last suggestion: When working locally, it helps if you can skip the whole email process. While SpoolMail is helpful, I'd rather just get the error immediately. What I do then typically is check the server name CGI variable. If it is my local version, I dump the exception to screen.


Ray Camden - making the world smarter by showing how much he doesn't know.
p.s. Check this blog for a very important announcement later today.
<cffunction name="onError">
<cfargument name="Exception" required="yes" />
<cfargument name="EventName" type="string" required="yes" />
<!--- Watch out for "coldfusion.runtime.AbortException" errors that result from <cfabort> and <cflocation> tags --->
<cfif arguments.exception.rootcause.type neq "coldfusion.runtime.AbortException">
<!--- Construct error message --->
<cfsavecontent variable="mailMessage">
<!--- Mail message goes here (can be in html format) --->
</cfsavecontent>
<!--- Invoke Mail component (my CFC for sending emails) and send email --->
<cfinvoke
component="#Application.config.componentPath#.Mail"
method="sendMail"
returnvariable="sentStatus">
<cfinvokeargument name="toEmail" value="foo@foo.com"/>
<cfinvokeargument name="fromEmail" value="foo@foo.com"/>
<cfinvokeargument name="fromName" value="foo foo"/>
<cfinvokeargument name="subject" value="An error occured in website"/>
<cfinvokeargument name="message" value="#mailMessage#"/>
<cfinvokeargument name="htmlFormat" value=true />
</cfinvoke>
<!--- If the error didn't occur in the "onSessionEnd" and "onApplicationEnd" event handlers display error page --->
<cfif NOT (arguments.EventName EQ "onSessionEnd") OR (arguments.EventName EQ "onApplicationEnd")>
<!--- Redirect to error template --->
<cflocation url="errorTemplate.cfm" addtoken="no" />
</cfif>
</cfif>
</cffunction>
The mail message in the <cfsavecontent> tag could be in this format
<cfsavecontent variable="mailMessage">
<cfoutput>
<h3>An error occcured on the website, foo.com</h3>
<p>The error information is given below.</p>
<div style='background-color:##FDFFEF;border:1px solid ##ECEFD1; margin-top: -0.3em; padding: 8px; margin-bottom: 0.3em; color: ##666666; font-size:13px; font-family:"Tahoma, Verdana"'>
<p><b>ERROR INFORMATION</b></p>
<p><strong>Page : </strong> #cgi.SCRIPT_NAME#</p>
<p><b>Error Type : </b>#arguments.Exception.type#</p>
<p><b>Error Message : </b>#arguments.Exception.message#</p>
<p><b>Error Details : </b>#arguments.Exception.Detail#</p>
<p><strong>ROOT CAUSE </strong></p>
<p><strong>Type : </strong>#IIf(arguments.exception.rootcause.type neq "",Evaluate(DE("arguments.exception.rootcause.type")),DE("None"))#</p>
<p><strong>Message : </strong>#IIf(arguments.exception.rootcause.message neq "",Evaluate(DE("arguments.exception.rootcause.message")),DE("None"))#</p>
<p><strong>Detail : </strong>#IIf(arguments.exception.rootcause.detail neq "",Evaluate(DE("arguments.exception.rootcause.detail")),DE("None"))#</p>
<cfdump var="#arguments.exception.rootcause.tagcontext#" />
<p><strong>Date and time : </strong> #TimeFormat(now(),"short")# #DateFormat(now(),"full")# <br>
<strong>IP Address : </strong> #cgi.REMOTE_ADDR# <br>
<strong>Browser : </strong> #detectBrowser()#<br>
<strong>HTTP Referer : </strong> #IIf(cgi.HTTP_REFERER neq "",Evaluate(DE("cgi.http_referer")),DE("None"))#<br></p>
</div>
<p>-----------------------------------------------------------------------------</p>
<p style='color:##666666; font-size:11px; font-family:"Verdana"'>foo foo<br/><br/><br/><a href="foo.com">foo.com</a></p>
</cfoutput>
</cfsavecontent>
DK
Especially if you are looking at the same hostname that others are seeing.
[Add Comment] [Subscribe to Comments]