I am posting this as a discrepency to something I read in GEAR. The topic is Error Handling. While I generally abide by the standards set forth in GEAR, occasionally they do not mix well with my development architecure and I need to improvise. I will not explain how GEAR describes the process.
Scenario:
A B2B Flow is called via a browser and it invokes other flows, passing variables to them. The invoked Flows may, themselves, invoke other Flows, too. Any flows may fail and that failure must be caught and passed back to the originally-called Flow. The error message must include an identifying failure message which is displayed in the end-user’s browser.
Solution:
- Create a top-level sequence and label it (e.g. “topLevel”). Indicate this sequence to “EXIT ON DONE”.
- Create a sub-sequence of “topLevel”. Label the sub-sequence “TRY”. Indicate this sequence to “EXIT ON FAILURE”. This is your TRY block.
- As the last step of the TRY sequence, do EXIT and EXIT FROM “topLevel” and SIGNAL “SUCCESS”.
- Create a sub-sequence of “topLevel”. Label the sub-sequence “CATCH”. Indicate this sequence to “EXIT ON DONE”. This is your CATCH block.
- In the CATCH sequence, gather the exception data by invoking “getLastError” (pub.flow:getLastError). Do not map the output to a variable.
- Next, create a BRANCH step and switch on the variable generated by the “getLastError” invocation named “/lastError/pipeline/errorMessage”.
- Create a sequence and label it $NULL. Indicate this sequence to “EXIT ON FAILURE”.
- In the $NULL sequence, map the string “lastError/error” to a new string variable “errorMessage”.
- Generate a Date-Time Stamp using “pub.date:currentDate” and map the output to a string variable named “dateTime”.
- Create two string variables named “errorMessage” and “serviceThrowingError”. Populate these variables with the nature of the error and with the name of the B2B Flow you are currently editing, respectively. De-select the option to “Overwrite Pipeline Variable” for “errorMessage”.
- As the other step of BRANCH, create a MAP step and label it “$default”.
- In the Pipeline Out pane, assign the following variables: errorMessage == %/lastError/pipeline/errorMessage%; serviceThrowingError == %/lastError/pipeline/serviceThrowingError%; dateTime == %/lastError/pipeline/dateTime%. Be sure to select “Perform Variable Substitution” in the dialog box.
- As the step following BRANCH, do EXIT and indicate the EXIT to exit from “$FLOW” and SIGNAL “FAILURE”.
As a crude graphic, the flow looks like this:
SEQUENCE: topLevel
–SEQUENCE: TRY
----[INSERT PROCESSING]
----EXIT “topLevel” and SIGNAL “SUCCESS”
–SEQUENCE: CATCH
----getLastError
----BRANCH: /lastError/pipeline/errorMessage
------SEQUENCE: $NULL
--------MAP lastError/error to “errorMessage”
--------Generate Date-Time Stamp
--------Populate variables “errorMessage” and “serviceThrowingError”
------MAP: $DEFAULT errorMessage, serviceThrowingError, and dateTime with pipeline variables
------EXIT “$FLOW” and signal “FAILURE”
If you implement this same structure in each of your B2B Flows, an error will be passed back the browser and will contain the three variables describing the state of the transaction when the error occured – errorMessage, serviceThrowingError, and dateTime.