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
    ------------------------------