Build a service response¶
Accumulates categorized success, warning, error, and environment messages into a ServiceResponse for
service-style managers, and converts caught exceptions into environment messages.
| Field | Value |
|---|---|
| Operation ID | build-a-service-response |
| Trigger | A service-style manager derived from clsServiceAppManagerBase completes a unit of work |
| Inputs | Messages added during processing; optionally a caught Exception |
| Outputs | Result flag plus categorized message collections |
| Primary components | ServiceResponse |
| Entry point | SAIF.Application/Service Based/ServiceResponse.vb |
Steps¶
- A new
ServiceResponsestarts withResult = Trueand an empty message list (BR-APP-009). - Processing code calls
AddErrorMessage/AddWarningMessage/AddInformationMessage/AddEnvironmentMessage, each wrapping the text and optional key in aServiceMessageof the correspondingServiceMessageType. - On an exception,
ProcessException(ex)recordsex.Messagekeyed byex.GetType.Nameas anEnvironmentmessage, then walks the inner-exception chain doing the same. - Consumers read
Errors,Warnings,InformationalMessages, andEnvironmentalErrors, which are LINQ filters over the single orderedMessageslist. Resultis a public field never modified by this class — the caller is responsible for setting it toFalsewhen errors are present (BR-APP-009).
Process flow¶
The following diagram visualizes this operation's control flow.
flowchart TD
Start(["ServiceResponse<br>created: Result=True"]) --> Process["Processing code adds<br>Error/Warning/Info/Env<br>messages"]
Process --> Exception{"Exception<br>caught?"}
Exception -->|Yes| ProcessEx["ProcessException:<br>walk inner-exception chain"]
Exception -->|No| Read["Consumer reads<br>Errors/Warnings/Info/<br>EnvironmentalErrors"]
ProcessEx --> Read
Read --> SetResult["Caller sets Result<br>= False if needed"]
Failure and edge-case behavior¶
- Defect: the inner-exception loop re-assigns
LocalEX = ex.InnerException(the outer exception) instead ofLocalEX.InnerException, so any exception with a non-Nothinginner exception causes an infinite loop that appends the same message repeatedly.**