Link to home
Start Free TrialLog in
Avatar of kitten47
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.RemoteAddress#', '#Error.Browser#', '#Error.DateTime#','#Error.HTTPReferer#','#Error.Template#','#Error.Diagnostics#')
</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
Avatar of Drewbytes
Drewbytes

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kitten47
kitten47

ASKER

Thank you. It was because my Error.HTTPReferer was empty.
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>