onException vs onError

40 views
Skip to first unread message

Jae Jung

unread,
Sep 23, 2016, 12:38:43 PM9/23/16
to ColdBox Platform
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.

Luis Majano

unread,
Sep 23, 2016, 1:39:24 PM9/23/16
to ColdBox Platform
--
--
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
For News, visit http://blog.coldbox.org
For Documentation, visit http://wiki.coldbox.org
For Bug Reports, visit https://ortussolutions.atlassian.net/browse/COLDBOX
---
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coldbox+u...@googlegroups.com.
To post to this group, send email to col...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/coldbox/5ece482e-3733-47e3-8d82-7d61c6dce820%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jae Jung

unread,
Sep 23, 2016, 1:48:02 PM9/23/16
to ColdBox Platform
I used the documentation to build the onError. However, my question is if I wanted to use the ColdBox error template BugReport.cfm in onError then the value arguments.exception can't be used. Is there an alternative?

Ancient Programmer

unread,
Sep 26, 2016, 1:01:58 AM9/26/16
to ColdBox Platform
When I dumped the
arguments
scope in onError(), arguments.expection is empty/null. It might be a bug.

Alternatively, you can get the exception from
 arguments.prc.exception
, e.g. writeDump(arguments.prc.exception.getMessage());

Luis Majano

unread,
Sep 26, 2016, 9:42:57 AM9/26/16
to col...@googlegroups.com
On error is by convention on handlers. Is this where you are coding this?


Luis Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com
P/F: 1-888-557-8057

--
--
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
For News, visit http://blog.coldbox.org
For Documentation, visit http://wiki.coldbox.org
For Bug Reports, visit https://ortussolutions.atlassian.net/browse/COLDBOX
---
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coldbox+u...@googlegroups.com.
To post to this group, send email to col...@googlegroups.com.

Jae Jung

unread,
Sep 26, 2016, 10:26:37 AM9/26/16
to ColdBox Platform
Although I didn't get an exact answer this discussion helped me to look into the right direction. I was trying to reuse the BugReport.cfm located at 

/coldbox/system/includes/BugReport.cfm. However, that template assumes the exception was set in the object coldbox.system.web.context.ExceptionBean. In order to reuse the template I has to initialize and set the exception data in the object coldbox.system.web.context.ExceptionBean. Below was the code I ended up writing.




var exceptionBean = createObject("component","coldbox.system.web.context.ExceptionBean").init(errorStruct=arguments.exception,extramessage=arguments.extramessage,errorType=arguments.errorType);
var bugreport= "";
savecontent variable="bugreport" {
    include "/vims/views/handlerBugReport.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);


This discussion definitely helped me to think outside the box. Thank you all for your help.

Jae



On Friday, September 23, 2016 at 12:38:43 PM UTC-4, Jae Jung wrote:
Reply all
Reply to author
Forward
0 new messages