The MSPro Boomi Collection
About
Good Practices & Patterns
Good Practices & Patterns
  • Markus' Boomi Integration
  • Implementation Patterns
    • The Cache Challenge
      • The Get-Or-Create Use-Case
      • PropCache Scripts
    • State Management
      • Example Scenario
      • State-Management in general
      • State-Management Functionality
      • Technical Solutions
        • Boomi File-System Implementation
          • saveState
          • readState & fetchStates
    • Exception Handling
      • Exception vs Error
      • Basic Rules
        • Aggregating Exceptions
      • Exception Handling Pattern
        • User-Defined Exception Messages
        • Catch Exceptions
      • The pattern in practice
        • API Error Handling
          • Single Record Strategy
            • Single Record RES
          • Many Records Strategy (Array)
            • Many Records RES
        • Pre-Condition Check
    • SQL Patterns
      • Script Header
      • General Rules
        • Check using RowCount
        • Check if record exists
        • Pagination and Sorting
        • Parameter - Best Practices
        • Use JSON as a complex parameter
    • Process Patterns
      • Process Route Implementation Pattern
      • Sub-Process or Process Route
    • DateTime
      • The Boomi datetime dilemma
      • Database and Flow
      • Groovy
      • Data Hub
      • Get Current Date
    • Groovy Script Patterns
      • Dynamic Document Properties
      • Dynamic Process Properties
      • Documents
    • Array Elements to Documents
  • MSPro Services
    • Intermediate Storage
      • Example Processes
        • Docs 01 - Update and Create
          • sub.SampleData.Invoice
        • 02 - Upsert and Get
    • Render Templates
  • Tips
Powered by GitBook
On this page
  • Exception Base Class
  • The ParseExceptionMessage Script
  1. Implementation Patterns
  2. Exception Handling
  3. Exception Handling Pattern

Catch Exceptions

Last updated 6 months ago

In the Catch block we encounter two different scenarios:

  • a controlled exception has been caught or

  • an uncontrolled exception has been caught.

We want to treat both situations equally in the catch block.

  1. Set DDP_TryCatchMessage = Document Property - Base - Try/Catch Message

  2. Call The ParseExceptionMessage Script

  3. Use the created Dynamic Document Properties to handle the Exception.

Exception Base Class

In case of an uncontrolled exception, the script passes through the Try/Catch Message in DDP_rootCause=DDP_TryCatchMessage. The property name is fix, and that is why you user-defined exception messages should contain a "rootCause" element, so that you can access the error message through that property, no matter if the exception was controlled or uncontrolled.

DDP_userMessage is set to "Something went wrong! Please contact your admin!".

The ParseExceptionMessage Script

Source Code on GitHub

The script parses an exception message (expected in [DDP_TryCatchMessage]) 
and sets well-defined document properties. If [DDP_TryCatchMessage] does not contain a
structured error Json, [DDP_TryCatchMessage] is routed to [DDP_rootCause] property.

If [DDP_TryCatchMessage] is not set the script throws an exception.

The [DDP_TryCatchMessage] must start with "Exception:" (case-sensitive) so that the script runs.
The script parses the following text into dynamic document properties as follows:

    Exception: {DDP_ExceptionType}
    {DDP_ExceptionJson}

The [DDP_ExceptionJson] is then interpreted as JSON and all elements on the first level 
will be turned into dynamic document properties, too. All nested elements are skipped when creating DDPs.
For example:
    DDP_TryCatchMessage=
        Exception: ApplicationException
        {
            "statusCode" : 404,
            "rootCause" : "Record not found!"
        } 
    
    DDP_exceptionType='ApplicationException'
    DDP_exceptionJson='{
        "statusCode": 404,
        "rootCause": "Record not found!"
    }'
    DDP_statusCode ='404'
    DDP_userMessage='Something went wrong! Please contact your admin!'
    DDP_rootCause  = 'Record not found!'
Create a j.Error.RESponse message as the result of an Exception