Trouble using renderData for 404 error page

Hi Experts,
My error handler does a 302 redirect, then returns statusCode 200 with the error page, i’d like it to return 404 with no redirect, but I’m having trouble

my current settings in ColdBox.cfc are

//Error/Exception Handling
exceptionHandler = “Main.onException”,
onInvalidEvent = “”,
customErrorTemplate = “”,

Main.onException logs the error then does a setNextRoute(‘error’)

my routes.cfm has this for it
addRoute(pattern=‘error’, handler=“Main”, action=“showError”);

then my showError function ends with
Event.setView(‘general/page/main_error’);

I tried replacing the setView with
event.renderData(data=renderView(‘general/page/main_error’),statusCode=404,statusMessage=“Page Not Found!”);

but it returns blank. I’ve also tried adding main.showError to my onInvalidEvent setting, and have tried replacing setNextRoute() with runEvent() to get rid of the 302, but those don’t work either

thanks for the help!!

  • Rob

Is this code in the main.onexception

signature0.jpg

Luis F. Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano

thanks for the help guys
the code in my main.onException logs the error, then does a setNextRoute performing a 302 redirect to my ‘error’ page.
my ‘error’ page hits main.showError which tries to fix the request, then if it can’t - it gives a friendly error page in our layout.main and setView. The problem is that shows 200, so i’m afraid google actually indexes it.

brad you raise a very good point - it would be nice if i could analyze what caused the error and insert the proper statusCode, instead of always doing a 404. I was hoping after I got 404 to work then i could make it smarter and figure out how to apply other codes

i haven’t tried using the customErrorTemplate yet - maybe that’s what I’m missing. I think a friendly error page inside our layout is a better user experience, so that’s my goal.

I’m sure the majority of our customers are using whatever default setting their browser has for ‘friendly error messages’ - that might be a deal-breaker if my 404 forces an ugly IE 404 page. I choose user-experience over google index optimization

thanks again

  • Rob