Trapping missing Fuseactions in Fusebox no XML

August 11, 2008

A while ago I wrote a post Trapping missing Fuseactions in Fusebox, this was for the XML version of Fusebox and allowed you to trap an invalid fuseaction and redirect to a nice page. Unfortunately this doesn't work with the no XML style of writing Fusebox powered applications. The reason for this is that when you don't define your fuses and circuits with XML, then Fusebox auto-discovers the circuits and fuses as they are called. In other words you can't check to see if it exists before it's been discovered.

Fusebox does have in-built error handlers, which handle invalid fuses or circuits. If you've ever used them you'll know that they are not particularly user friendly. You could style the errorhandlers, which is not ideal as multiple sites could share the core files. I prefer to trap the exception in Application.cfc.

When Fusebox tries to execute an invalid fuseaction it throws one of these errors:

So all we need to do in our onError method of Application.cfc is:

<cffunction name="onError" 
  returntype="void" 
  output="true" 
  access="public" 
  hint="I am executed when an unhandled error occurs">

  <cfargument name="exception" 
    type="any" 
    required="true" />
  <cfargument name="eventName" 
    type="string" 
    required="true" />
	
  <cfif IsDefined("exception.Cause.Message")
    AND ListFindNoCase("undefined Circuit,undefined Fuseaction,malformed Fuseaction", exception.Cause.Message) gt 0>
    <!--- invalid fuseaction --->
    <cfcontent reset="true" type="text/html" />
    <cfheader statuscode="404" statustext="Not Found" />
    <!--- show 404 page or could redirect --->
    <cfoutput><cfinclude template="404.html" /></cfoutput>
  <cfelse>
    ... normal error handling ...
  </cfif>
</cffunction>


No comments

Leave a comment

If you found this post useful, interesting or just plain wrong, let me know - I like feedback :)

Please note: If you haven't commented before, then your comments will be moderated before they are displayed.