Orange is my favorite color

I’ve been working on my exception reports and one of the things I wanted to do was isolate the equivalent of a “404″ response in Model-Glue to be more graceful to the user. I found this post from Ray’s site and a promise in the comments from Joe Rinehart that typed exceptions would make their way into the final MG release but apparently it never happened.

It turns out this is a pretty easy thing to add yourself and it only requires adding about 30 characters to a single line of a single file. Replace line 45 in ModelGlue/unity/eventhandler/EventHandlerRegistry.cfc with:

<cfthrow type="ModelGlue.UnknownEvent" message="Model-Glue: There is no known event handler for ""#arguments.name#""." />

Now MG will throw the ModelGlue.UnknownEvent exception. I just made this up – you could name it whatever you like. Then using your exception handler, you can test for this particular exception like so:

<cfif structKeyExists(exception, "type") AND exception.type EQ "ModelGlue.UnknownEvent">
// 404 type handler
<cfelse>
// everything else
</cfif>

Your 404 handler can be quite robust including looking for misspellings, checking for broken IDs in URLs, looking up similar types of events and so forth. I’m just displaying a “Broken Link” message for now. Anyone have any other clever 404 handling ideas?

2 Comments

  1. Antony said:

    on May 15, 2008 at 4:09 am

    Hi – I parse the error message. If it contains ‘no known event handler’ I figure that’s a url typo. Pretty low tech…

  2. brian said:

    on May 15, 2008 at 10:40 am

    That definitely works but this feels more “clean” to me plus it uses the exception handling mechanisms ColdFusion was designed with.

{ RSS feed for comments on this post}