Decision Management (ODM,ADS)

 View Only
Expand all | Collapse all

How to set the custom exception object in the response from CustomExceptionHandler in ODM

  • 1.  How to set the custom exception object in the response from CustomExceptionHandler in ODM

    Posted Tue January 16, 2024 03:07 PM

    How to set the custom exception object in the response from CustomExceptionHandler in ODM?

    I am in the process of migrating ODM 8.9.2 rules to 8.12. I would like to set custom exception message and code and send it back in the response object. But would like to get some guidance on how to pass the response object to the Custom Exception Handler class.



    ------------------------------
    Anishia Casmir Thomas
    ------------------------------


  • 2.  RE: How to set the custom exception object in the response from CustomExceptionHandler in ODM
    Best Answer

    Posted Tue January 16, 2024 05:31 PM
      |   view attached

    You can access the response object explicitly from the handleActionException method using the RuleInstance argument to retrieve a parameter

    For example 

      response = (Response) ruleInstance.getEngineData().get("response");
    In the method handleConditionException there is no way to access the engine directly.
    You can use a side effect to initialize the local attribute response with an action exception and reuse it in the handleConditionException method afterward.
    You can refine the process by creating a rule that is called at the beginning of the ruleflow and intentionally throws an exception:
    when {
      c : IlrContext() from ?context;
    }
    then {
      throw new Exception( "initializing exception handler");
    }
    In the handleActionException you initialize the object response you want to reuse and ignore the exception because ruleInstance.getRuleName() equals the name of the rule created to fail.


    ------------------------------
    Alain Robert
    ------------------------------

    Attachment(s)

    zip
    exceptionhandler.zip   18 KB 1 version


  • 3.  RE: How to set the custom exception object in the response from CustomExceptionHandler in ODM

    Posted Tue January 16, 2024 07:55 PM

    Thanks Alain for your quick response, was able to get the response object from the EngineData :)Appreciate your quick response :)



    ------------------------------
    Anishia Casmir Thomas
    ------------------------------



  • 4.  RE: How to set the custom exception object in the response from CustomExceptionHandler in ODM

    Posted Wed October 23, 2024 06:03 AM

    Hi @Alain Robert, I come to this searching the community because we have implemented the same pattern that you're proposing here to initialize the
    exception handler with one of the output parameters of the ruleset and it is not working well.

    I don't know if you have access to this support case where I have uploaded a simplified project to reproduce the problem.

    The issue is that DE is creating more than one instance of the exception handler, so that, when the exceptions are managed,
    the handler is not the one initialized with the output parameter.

    I don't know if it's ever happened to you.



    ------------------------------
    Eduardo Izquierdo Lázaro
    Automation Architect
    DECIDE
    Madrid
    609893677
    ------------------------------