Extending Mura CMS with Plugins - Part V - Handling Plugin Errors
Posted At : February 10, 2010 3:20 PM | Posted By : Bob Silverberg
Related Categories:
ColdFusion,Mura CMS
Here's a quick Mura Plugin tip: You can handle errors in your plugin via an onError() event in your event handler. Here's what mine looks like:
<cfargument name="event">
<cfif arguments.event.getConfigBean().getDebuggingEnabled()>
<cfdump var="#arguments.event.getValue('error')#" />
<cfelse>
<cfset arguments.event.getServiceFactory().getBean("MuraService").SendErrorEmail(arguments.event.getValue("error")) />
<cfinclude template="../displayObjects/util/dspPluginError.cfm" />
</cfif>
</cffunction>
What's going on in there?
First I'm checking to see if debugging is enabled in the global config by checking the value of event.getConfigBean().getDebuggingEnabled(). If debugging is enabled I want to display the information about the error on the page, so I'm dumping the contents of the error key from the event. If debugging is not enabled, then I want to send an email to the site administrator, which is done by invoking a method on my MuraService object, which is defined in my Coldspring config. After that I want to display a friendly error message to the user, so I simply include a template from the displayObjects/util/ folder of my plugin. This allows the plugin itself to control what sort of message is displayed to a user when an error occurs.
Pretty simple, eh?







There are no comments for this entry.
[Add Comment]