Howie Hamlin wrote:
> Does anyone have a good site-wide error handler template that I can use?  I would
>like to log error details and optionally email the errors at the same time.

Here's one I'm playing around with right now.  I'm curious if anyone
knows if this would work in CF5?

It determines which scopes exist, and uses cfsavecontent and cfdump to
save error files to disk at the location you choose.  It will
optionally email those files as attachments

This code is self-contained, but you can set its parameters in your
individual apps too if you like.  I'm planning on setting the email
var in individual locations inside of specific templates so if
sensitive data would wind up being dumped, sending an email with the
attachment is defeated.  You could also skip the 'else' email entirely
here.

HtH,

--
--Matt Robertson--
MSB Designs, Inc.
mysecretbase.com

<cfscript>
variables.sendEmail="";                      // Y=send email or leave
blank for no xmit
variables.emailTo="[EMAIL PROTECTED]";
variables.emailFrom="[EMAIL PROTECTED]";
variables.emailServer="mail.lelandwest.com";
variables.vars="APPLICATION,ARGUMENTS,ATTRIBUTES,CALLER,CFCATCH,CGI,CLIENT,COOKIE,ERROR,FLASH,FORM,REQUEST,SERVER,SESSION,THIS,THISTAG,URL,VARIABLES";
variables.theFileName=Replace(CreateUUID(),"-","","all");
variables.errorDirectory="c:\cfusionmx\wwwroot\";
</cfscript>
<cfsavecontent variable="variables.errorDump">
<cfloop
list="#variables.vars#"
index="loopItem">
<cfif IsDefined("#loopItem#")>
<cfdump
var="#Evaluate(loopItem)#"
label="#loopItem#">
</cfif>
</cfloop>
</cfsavecontent>
<cffile
action=""
file="#variables.errorDirectory##variables.theFileName#.html"
output="#variables.errorDump#">
<cfif len(variables.sendEmail)>
<cfmail
to="#variables.emailTo#"
from="#variables.emailFrom#"
subject="Error Alert"
server="#variables.emailServer#"
type="HTML"
mimeattach="#variables.errorDirectory##variables.theFileName#.html">
Error dump attached.
</cfmail>
<cfelse>
<cfmail
to="#variables.emailTo#"
from="#variables.emailFrom#"
subject="Error Alert"
server="#variables.emailServer#"
type="HTML">
<p>An error occurred:<br>
#variables.theFileName#.html
</p>
</cfmail>
</cfif>
show friendly oops display to user here
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to