Thursday, December 03, 2015

Why does my onError() fail on Request Timeout?

So I guess today has become a day of tuning some things that have always driven me crazy. One of them was that when an error would happen on one of my sites and it was based on a request timeout I would not get my nice little error notification and users or clients would send me a screenshot of an IIS error template with ColdFusion dumping its ugly error in their face. This has always been quite embarrassing for me but then I would get busy doing other things and forget about it.

So this is an example of what I am talking about ...



In validating that we can keep learning something new everyday, I had no idea that in an error I can go ahead and increase the timeout for that request, allowing just enough time for my onError() function to process.

I figured this out because I did an abort as the first line of my onError() function and the error page did not show up, letting me know that it did execute. I then tried to do a writeDump() and the ugly error showed its face again. I then decided to do a cfsetting, thinking it would fail and to my surprise that worked. At this point I was hardcoding a new requesttimeout but I wanted it to not fail even on pages that already had larger request time out settings.

I needed a way to increase my current timeout setting and apparently executing a createObject could also be done. Thanks to Brian Ghidinelli for this post from 2009 on how to get the current RequestTimeout.

So in the end I did the following and now I do get my nice error notifications and my users never see that ugly error page again!

Disclaimer : The code above is only supported on ColdFusion 11 + as cfsetting is not supported in cfscript prior. If your Application.cfc is written in tags then you should have no problem writing the equivalent and if it is in cfscript you can include a template (also works) that simply has the cfsetting in tag.

Also for anyone that may want to test this on their own code, you can add the following on any template to fire off the request timeout error

No comments:

Post a Comment