
| home | AJAX (8) || C#.NET (7) || Coldfusion Development (16) || DHTML (15) || Flash Development (19) || jQuery (8) || MSSQL (2) || UNIX (10) |
| 5.21.07 | Capture All Coldfusion Errors in CFAJAX |
Ever been stuck with a CFAJAX-driven application that throws a CFERROR that causes the AJAX application to “break” when it comes to the user-experience…?
One problem with the development cycle and regression testing of CFAJAX-based applications is the inability to easily “capture” errors as they happen in the Coldfusion code that makes up the actual AJAX handler. When building a CFAJAX application, it is easy to break the flow of the interface from the users’ perspective when the AJAX handler throws a Coldfusion error and the actual javascript end doesn’t know how to handle it.
To solve this, I simply had the AJAX handler code return a default CFAJAX error back to the javascript side of the application if a CFERROR was thrown. A simple way to take care of this is to add the return into the Application.cfc’s onError function. This means that any error thrown in the application that contains the AJAX handler, a default CFAJAX error will be sent to the javascript end so that the end user will be more informed and the AJAX application itself will not leave them guessing.
I use the following code in my Application.cfc ONLY for the actual Coldfusion CFAJAX handler itself:
<cfset errorText = "
****/
DWREngine._handleResponse('ERROR', 123, true, false, true);
/* EOF CFAJAX */
/* ERROR DEBUG
Detail: #Trim(arguments.Except)#
*/
">
<!--- clear the output and send the fetched error message HTML --->
<cfset getPageContext().getOut().clearBuffer()>
<cfset writeOutput(errorText)>
<cfset getPageContext().getOut().flush()>
</cffunction>
</cfcomponent>
Download this code: cfajax-errorCapture-Application.cfc
No comments