Error when cflocation is ran within onRequestStart

There is some code in one of the projects I am working on that checks if a user is logged in within the onRequestStart application function. If the user is not logged in, the code redirects them to the login page using a cflocation. Although there is no visual error, i kept getting error emails thru my onError function stating there was a coldfusion.runtime.AbortException error happening:

An exception occurred when invoking a event handler method from Application.cfc The method name is: onRequestStart.

Reading various posts on this error on the web, I found that the this problem is well known and found some work-arounds. Here is one of them...

Within your onError function you can filter out the AbortException errors by doing this:

<cffunction name="onError" returntype="void">
   <cfargument name="exception" required="true">
   <cfargument name="eventname" type="string" required="true">

   <cfswitch expression="#arguments.exception.rootcause.type#">
      <cfcase value="coldfusion.runtime.AbortException">
         <!--- do nothing --->
         <cfreturn />
      </cfcase>
      <cfdefaultcase>
         <!--- error handling code here --->
         <cfdump var="#exception#" label="Exception">
      </cfdefaultcase>
   </cfswitch>
   
</cffunction>

That did the trick!

  1. Cornelius

    #1 by Cornelius - August 4, 2010 at 5:13 AM

    Thank you, that helped me a lot. Obviously it is not even a bug, but a standard procedure from Coldfusion, to send an Error when aborting from within an Application cfc Method. Either by cflocation or cfabort for example.
  2. Brad

    #2 by Brad - March 24, 2011 at 11:39 AM

    Thank you very much, had the same problem and this resolved it.
(will not be published)
Leave this field empty: