kitten47
asked on
cferror exception type using a database query to log errors
My question is: is it possible to log errors to a database when redirecting an exception error to a template page using <cferror type="exception" ...>. From what I've read out on the net, it should work, right?
In my application.cfm file I have the entry:
<cferror type="exception" template="errorpage.cfm" exception="Expression">
The errorpage.cfm file has a database query that is supposed to log the error specifics to a database. However instead of making the database connection, it displays the error diagnostics from the page that threw the exception.
Here is the contents of errorpage.cfm:
<html>
<head>
<title>We're sorry -- An Error Occurred</title>
</head>
<body>
<b><font face="verdana, arial, helvetica" size="3">We're Sorry. An Error Has Occured.</font></b>
<hr>
<cfoutput>
Sorry an error has occured. <a href="#mainpage#">Click here</a> to try continue.
</cfoutput>
<CFQUERY NAME="recordError" DATASOURCE="#datasrc#" DBTYPE="ODBC">
INSERT INTO Fatal_Errors(Location_ip, Browser, Occured, Referrer_URL, Page, Error_Msg)
VALUES('#Error.RemoteAddre ss#', '#Error.Browser#', '#Error.DateTime#','#Error .HTTPRefer er#','#Err or.Templat e#','#Erro r.Diagnost ics#')
</CFQUERY>
</body>
</html>
I don't know what I'm doing wrong and I'm beginning to doubt that this can be done at all. Any comments?
In my application.cfm file I have the entry:
<cferror type="exception" template="errorpage.cfm" exception="Expression">
The errorpage.cfm file has a database query that is supposed to log the error specifics to a database. However instead of making the database connection, it displays the error diagnostics from the page that threw the exception.
Here is the contents of errorpage.cfm:
<html>
<head>
<title>We're sorry -- An Error Occurred</title>
</head>
<body>
<b><font face="verdana, arial, helvetica" size="3">We're Sorry. An Error Has Occured.</font></b>
<hr>
<cfoutput>
Sorry an error has occured. <a href="#mainpage#">Click here</a> to try continue.
</cfoutput>
<CFQUERY NAME="recordError" DATASOURCE="#datasrc#" DBTYPE="ODBC">
INSERT INTO Fatal_Errors(Location_ip, Browser, Occured, Referrer_URL, Page, Error_Msg)
VALUES('#Error.RemoteAddre
</CFQUERY>
</body>
</html>
I don't know what I'm doing wrong and I'm beginning to doubt that this can be done at all. Any comments?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I was going directly to the page so there was no referrer URL.
For anyone else who might have this problem, here's the code I used to fix it:
<cfif Error.HTTPReferer is "">
<cfset Error.HTTPReferer = "none">
</cfif>