Connecting Tech Pros Worldwide Help | Site Map

How can I pass cferror info to a component?

Haitashi's Avatar
Member
 
Join Date: Jun 2007
Location: Orlando, FL
Posts: 94
#1: Nov 12 '07
I created a component that sends me an email every time an error occurs on my website.

I did a cftry and if that fails it passes the following params to that component:
Expand|Select|Wrap|Line Numbers
  1. <cfinvokeargument name="oFusebox" value="#myfusebox#" />
  2. <cfinvokeargument name="oClientError" value="#request.oClientError#" />
  3. <cfinvokeargument name="oCfcatch" value="#cfcatch#" />
However, I need to pass also the information inside cferror.
Not entirely sure how to do this.

Any ideas?
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Nov 13 '07

re: How can I pass cferror info to a component?


What information do you need to pass?

The error or cferror variable should contain the error info.
Haitashi's Avatar
Member
 
Join Date: Jun 2007
Location: Orlando, FL
Posts: 94
#3: Nov 13 '07

re: How can I pass cferror info to a component?


I wanted to get an email with information about the error. Like when and where it happened.

We're using the Fusebox framework with our app.

What I did to solve this was that I created a an cferror.cfm template/component. In that template I created an object and called it oErrorDetails. Now, there are two ways that information is going to get passed into that object. One is if an error occurs and another is a using a try/catch.

The component is called Alerts.

When an error occurs I don't have to worry about because it will take care of itself by calling the cferror template(because that's the template specified to handle errors). But I can also use that component with my try/catch. For example:

Expand|Select|Wrap|Line Numbers
  1. <cftry>
  2.         <cfset Variables.temp = Variables.oStaffMember.load(Variables.nAdTeacherID) />
  3.     <cfcatch type="API.LXD.Validation">
  4.         <cfset Variables.temp = Request.oClientError.setError("noStaffMember", "A Staff Member ID has not been loaded.") />
  5.  
  6.         <cfinvoke component="cfc.utility.facade.Alert" method="send" returnvariable="success">
  7.             <cfinvokeargument name="oFusebox" value="#myfusebox#" />
  8.             <cfinvokeargument name="oClientError" value="#request.oClientError#" />
  9.             <cfinvokeargument name="oErrorDetail" value="#cfcatch#" />
  10.         </cfinvoke>
  11.     </cfcatch>
  12. </cftry>
I passed the information contained in "cfcatch" to the component using cfinvokeargument.

It's great because the component emails me information about the error like:
#oErrorDetail.message# and I will get that information no matter if it's an error or just something I tested for using the try/catch.

I must point out that there are differences (obviously) between what information I can get when I use cferror vs try/catch. This is simply solved by testing if certain variables are defined.

Expand|Select|Wrap|Line Numbers
  1. <cfif IsDefined("oErrorDetail.template")>
  2. <tr>
  3.     <td class="label" nowrap="nowrap"><strong>Occurred in Template &nbsp; </strong></td>
  4.     <td>#oErrorDetail.template#</td>
  5. </tr>
  6.  
  7. </cfif>        
In the previous code, only if template in the oErrorDetail object is defined then we will get an email with that info. Otherwise, it will ignore it. This is because only cferror has that property - cfcatch, doesn't.

It took me while to figure this out. But I finally got it.
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#4: Nov 13 '07

re: How can I pass cferror info to a component?


Glad you got it working and thanks for posting a detailed solution. Good job!
Reply