Title: Message
I would look some ideas and comments on the following.
 
I have a CFC to handle errors, but I know that it is lacking a lot, and it's not written the way it should be, thus I would appreciate some insight and comments, so I can improve on this one.
 
Let's take for example the following code that would generate an error for a missing datasource
 
*********************************************
CODE
*********************************************
 
<cfparam name="request.error" default="#structNew()#" type="struct">
<cfparam name="request.error.message" default="#arrayNew(1)#" type="array">
<cfparam name="request.error.exceptionHandled" default="false" type="boolean">
<cfparam name="request.error.exceptionHandler" default="" type="string">
 
<!----------------------------------------------------------------------------------------------
 Initialize the application.
 Store client variables in the database.
------------------------------------------------------------------------------------------------>
<cftry>
<cfapplication name="app#request.applicationName#_#request.applicationPhase#"
  clientmanagement="yes"
  sessionmanagement="yes"
  setclientcookies="yes"
  setdomaincookies="no"
  sessiontimeout="#createTimeSpan(0,0,request.sessionTimeOut,0)#"
  applicationtimeout="#createTimeSpan(0,4,0,0)#"
  clientstorage="#variables.dsnMain#">
 <!--- Possible reasons for error: No Data Source, no valid Client Storage --->
 <cfcatch>
 
  <cfset request.error = server.component.objError.fnError( applicationName = request.applicationName, applicationPhase = request.applicationPhase, error = request.error, type = "#cfCatch.type#,datasource,clientStorage", variables = variables)>
  <cfif request.error.exceptionHandled>
   <cfset url.page = request.error.exceptionHandler>
  </cfif>
 
  <!--- If the exception is still not handled --->
  <cfif NOT request.error.exceptionHandled>
   <cfthrow message="There was an unknown problem while trying to initialize the application." type="tag.cfapplication">
  </cfif>
 </cfcatch>
</cftry>
*********************************************
END: CODE
*********************************************
 
The argument "type" is a list of possible problems, it includes the type reported by cfcatch, and some types that we possible think could be an issue.
 
The CFC is as following
 
*********************************************
CODE
*********************************************
 
<cfcomponent>
 <cffunction access="public" name="fnError" output="false" returntype="struct">
  <cfargument name="applicationName" type="string" required="true">
  <cfargument name="applicationPhase" type="string" required="true">
  <cfargument name="error" type="struct" required="true">
  <cfargument name="type" type="string" required="true">
  <cfargument name="variables" type="struct" required="false" default="#structNew()#">
 
  <cfloop index="errorType" list="#type#">
   <!--- Only handle one exception at a time --->
   <cfif NOT error.exceptionHandled>
    <cftry>
     <cfinclude template="/#applicationName#_#applicationPhase#/index/error/handler/#errorType#/err_handler.cfm">
     <cfcatch type="missinginclude">
      <cfset arrayAppend(error.message, "There is no mapping for /#applicationName#_#applicationPhase#/, please create the mapping first.")>
      <cfset error.exceptionHandled = true>
     </cfcatch>
    </cftry>
   </cfif>
  </cfloop>
 
  <cfreturn error>
 </cffunction>
</cfcomponent>
*********************************************
END: CODE
*********************************************
 
I personally don't like the idea of including templates to handle each possible error, I have the feeling I should be doing this with another CFC to extend on this one, but how exactly?
 
The handler for "datasource" looks like
 
 
*********************************************
CODE
*********************************************
<cftry>
<!--- Verify the Data Source, returns an error if it can't verify it --->
<cfset verifyDSN = server.component.sql.verifyDatasource( variables.dsnMain )>
 <cfcatch type="any">
  <cfset verifyDSN = "no">
 </cfcatch>
</cftry>
 
<!--- If the Data Source did not verify --->
<cfif NOT verifyDSN>
 <cfset error.exceptionHandler = "index.admin.application.datasource.add">
 <cfset arrayAppend(error.message, "There is no Main Data Source set-up, please create the Main Data Source for this application.")>
 <cfset error.exceptionHandled = true>
</cfif>
 
*********************************************
END: CODE
*********************************************
 
I just can't get my head around on how to proceed from here, I know that some of what I have is pretty well thought out, but I also know that some of it is just plain crap and could be done better.......
 
Taco Fleur
Blog http://www.tacofleur.com/index/blog/
Methodology http://www.tacofleur.com/index/methodology/

Tell me and I will forget
Show me and I will remember
Teach me and I will learn
 
---
You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]
MXDU2004 + Macromedia DevCon AsiaPac + Sydney, Australia
http://www.mxdu.com/ + 24-25 February, 2004

Reply via email to