Custom Error Handling

So whenever we have an issue on one of our sites (public facing), we get an error that looks like an array dump (unfortunately I’m not allowed to upload a picture of the error?). While this is great for debugging purposes, its not a very safe practice to have your database information out there for anyone in the public domain to have. Instead of allowing Farcry to dump this information, is there a way to have it redirect to a generic 404.cfm page?

This depends on your version of FarCry.

In version 7, you can do this very easily. A 500.cfm in either %project folder%\errors\ or %project webroot%\errors\ will be displayed instead of the error dump. Similarly a 404.cfm in the same place will be displayed when a page is not found.

Unfortunately, I’m not sure if this was implemented in version 6, but you can always give it a go with a simple test error page.

Good luck!

Unfortunately we are behind the times and working with FC 5.0.2. :weary:

I’ll be interested to hear what the other say, but I’d imagine that you’ll have to play around with the OnError function in %core%\Application.cfc.

One thing you could try is overriding the function by adding it to %project webroot%\Application.cfc, e.g.

<cffunction name="OnError" access="public" returntype="void" output="true" hint="Fires when an exception occures that is not caught by a try/catch.">

<cfargument name="Exception" type="any" required="true" />
<cfargument name="EventName" type="string" required="false" default="" />

<cfoutput>Ooops something went wrong!</cfoutput>
<!--- alter as desired --->

</cffunction>
1 Like

Awesome! That seemed to work. I tried putting the function in the %project%/Application.cfc file but it threw a 500 error. No worries though. I edited the cfc in the core. Works great now!

Here’s the code for anyone who is ever interested:

<cffunction name="OnError" access="public" returntype="void" output="true" hint="Fires when an exception occures that is not caught by a try/catch.">
	
    	<cfargument name="Exception" type="any" required="true" />
		<cfargument name="EventName" type="string" required="false" default="" />

		<!--- rudimentary error handler --->
		<!--- TODO: need a pretty error handler for the webtop --->
        <!---check for dev/UAT enviornment--->
		<cfif CGI.SERVER_NAME CONTAINS "stage" OR CGI.SERVER_NAME CONTAINS "dev">
            <cfinclude template="/farcry/projects/#application.projectDirectoryName#/webskin/includes/header.cfm" />
            <cfoutput>There was an issue with your request. Please contact us for assistance.</cfoutput>
            <cfdump var="#arguments.exception#" expand="true" label="arguments" />
            <cfinclude template="/farcry/projects/#application.projectDirectoryName#/webskin/includes/footer.cfm" />
		     
        	<cfreturn />   
   		<cfelse>     
			<cfinclude template="/farcry/projects/#application.projectDirectoryName#/webskin/includes/header.cfm" />
            <cfoutput>There was an issue with your request. Please contact us for assistance.</cfoutput>
           <cfinclude template="/farcry/projects/#application.projectDirectoryName#/webskin/includes/footer.cfm" />
		     
        	<cfreturn />
  
  		</cfif>
 </cffunction>

Glad you got it working :smile: A couple of words of warning though:

  1. If the error is in the header or footer includes, that particular error handler will break

  2. If/when you do upgrade FarCry, you will need to redo the error handling

I don’t think there’s any reason that the code would work inside the core/Application.cfc but not in your project’s Application.cfc (after all, your project’s Application.cfc just extends the one from core, via the proxyApplication.cfc). It might be worth another try so that you can avoid modifying the core files.

It would also be a good idea to consider upgrading to FarCry 7.x soon. FarCry 5.x is getting very old and is not really supported any more. Plus FarCry 7 is much nicer to use :smile: Depending on your app upgrading may be fairly straight forward.

1 Like

It’s on our list of projects waiting in queue :sweat: . We recently upgraded most of our sites to FC 7 (which is very amazing by the way!) but we ran into issues with our last two sites which are quite large. So the project had to be split into multiple phases because of the short time frame we had initially. Bleh. But definitely looking forward to having an up to date CMS!

By the way, would you know if there is any documentation as to how the admin portion of FC 7 works? I feel like we aren’t utilizing Farcry to the extent it could be…

1 Like