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:
2<cfargument name="event">
3
4<cfif arguments.event.getConfigBean().getDebuggingEnabled()>
5 <cfdump var="#arguments.event.getValue('error')#" />
6<cfelse>
7 <cfset arguments.event.getServiceFactory().getBean("MuraService").SendErrorEmail(arguments.event.getValue("error")) />
8 <cfinclude template="../displayObjects/util/dspPluginError.cfm" />
9</cfif>
10
11</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?
Thanks,
dutch