Photo from Chile

Extending Mura CMS with Plugins - Part V - Handling Plugin Errors

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:

view plain print about
1<cffunction name="onError" output="true" returntype="any">
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?

TweetBacks
Comments
Thanks for the tip. How would you apply error handling, in this manner, with the Mura FW/1 plugin.

Thanks,
dutch
# Posted By Dutch Rapley | 12/7/10 9:27 AM
It's been a long time since I've worked on a Mura plugin or done anything with the FW/1 plugin so I'm afraid I don't have an answer for your question. Sorry.
# Posted By Bob Silverberg | 12/13/10 3:07 PM