Quick Tip: Disable Error Handling on Dev Server
These days, I work with CF servers that are home to hundreds of applications simultaneously. We have some nice error reporting going on, with Application.cfc's onError() method to send email notifications, and using a backup of the CFError tags for when all else has failed. But I noticed that it was incredibly annoying waiting for error emails to arrive when my code would have an error in it. So I decided to disable custom error handling and pretty error pages in development.
Of course, to eliminate the potential for human error, we programatically determine if the application is running in dev, staging, or production:
<cfinvoke
component="cfc.AppStatus"
method="getEnvName"
returnVariable="appStatus"
/>
This code is in Application.cfc, and stores the result in a place shared with the entire application. We were already using this value to set things like the datasource password (which is different between your development and production environments, right?!). If it's not obvious, the function will return the string DEV, STAGE or PROD depending on which environment that server belongs to.
Then, in onRequestStart(), I added this little nugget:
<!--- If on dev, don't use error emails, just show errors --->
<cfif app_status neq "prod" and app_status neq "stage">
<cfset structDelete(this, "onError") />
<cfset structDelete(variables, "onError") />
<cfsetting showdebugoutput="true" />
</cfif>
And wrap the backup CFError tags like so:
<cfif app_status eq "prod" or app_status eq "stage">
<cferror
type="request"
template="/error_request.cfm"
/>
<cferror
type="exception"
template="/error_exception.cfm"
/>
</cfif>
Now, when my code throws an error while I'm developing and testing in the dev environment, I see it on screen instead of having to wait a minute or two for the email to come, and I don't have to worry about a rogue infinite loop filling up my inbox.
in Best Practices | ColdFusion | 2 Responses 2010-05-11 11:24
2 responses:
- Jake Munson 11 May 2010 5:17 PM Dude, where were you 2 months ago!? I spent many hours trying to do this for our apps, and I couldn't figure out how to tell the CF server to not run onError for certain conditions. I never thought about just deleting it from the this and variables scopes! Beautiful.
