I am trying to implement a custom error handling for each request made to the handler. I’m using the ColdBox exceptionHandler as follows.
`
function onException(event,rc,prc){
//Grab Exception From request collection, placed by ColdBox
var exceptionBean = event.getValue(“ExceptionBean”);
if (NOT isDebugMode()) {
var Exception = exceptionBean;
var bugreport= “”;
savecontent variable=“bugreport” {
include “/coldbox/system/includes/BugReport.cfm”;
}
//Place exception handler below:
dblogger.error(“MESSAGE:#exceptionBean.getExceptionStruct().message#, DETAIL:#exceptionBean.getExceptionStruct().detail#”,exceptionBean);
emaillogger.error(“MESSAGE:#exceptionBean.getExceptionStruct().message#, DETAIL:#exceptionBean.getExceptionStruct().detail#”,bugreport);
//location(url=’/site-error’, addToken=‘false’);
}
}
`
I would like to do the same for the onError in the handler. However, I can’t seem to use the event.getValue(“ExceptionBean”) thus not being able to use the default BugReport.cfm template. The code for the onError is as follows.
`
/**
- On Error
*/
function onError(event,faultAction,exception,eventArguments){
// prepare a data packet
var data = {
status = false,
error = ‘An error occurred. Please try again. If the problem persists please notify the system administrator.’
};
if (arguments.faultAction == ‘create’){
data[‘error’] = ‘An error occurred while creating the work request. Please try again. If the problem persists please notify the system administrator.’;
}else if (arguments.faultAction == ‘createNote’){
data[‘error’] = ‘An error occurred while creating the work request note. Please try again. If the problem persists please notify the system administrator.’;
}
var exceptionmessage = “#arguments.exception.message# & #arguments.exception.detail#”;
// log via the log variable already prepared by ColdBox
log.error(“Exception when executing #arguments.faultAction# #exceptionmessage#”, arguments.exception);
// render out a json packet according to specs status codes and messages
event.renderData(data=data,type=“json”,statusCode=400,statusMessage=“Error Occurred”);
}
`
The arguments.exception is not recognized in BugReport. How can I set the object rc.ExceptionBean? Any suggestions for the onError would be much appreciated.