Module 7 — Error Handling in Mule
This is one of the most important interview modules because integrations fail constantly in ways normal application code often doesn’t:
network timeout
Salesforce unavailable
bad credentials
rate limit
invalid Salesforce field
validation rule failure
partial batch failure
downstream API returns 500
request succeeded but response was lost
Your job is not merely to catch errors. It is to decide:
Which errors should stop the flow, which should be converted into a business response, and which are safe to retry?
Mule 4 handles flow-level errors through Error Handlers containing On Error Continue and On Error Propagate. Mule selects the first matching handler based on error type or expression.
7.1codeThe mental modelImagine:7.2Mule error typesYou'll encounter names like:7.3codeThe `error` objectInside an error handler you can inspect:7.4codeOn Error ContinueThis is Mule's:7.5codeOn Error PropagateThis means:7.6The distinction to memorizeInterview question:7.7codeFlow-level Error HandlerYou can attach an Error Handler to a flow.7.8codeHandler order mattersMule routes to the first matching handler.7.9code`ANY`ANY means essentially:7.10Error categories are more usefulFor an integration API, think:7.11codeNormalize errors into your API contractBad response:7.12codeExample error handlerConceptually:7.13Why On Error Continue can be dangerousImagine:7.14codeGood use of ContinueRequirement:7.15Bad use of ContinueRequirement:7.16codeThe Try scopeSometimes you don't want an error handler covering the entire flow.7.17Example Try scopeIf Loyalty fails:7.18Important Try behaviorIf a processor inside Try fails:7.19ExampleBilling fails.7.20Nested error handlingYou can have:7.21Global Error HandlerIf every API flow repeats:7.22Custom application errorsSuppose Salesforce says:7.23Why custom errors matterToday:7.24Until SuccessfulThis is Mule's important retry scope.7.25Critical Until Successful behaviorSuppose scope contains:7.26Better retry scopeInstead:7.27Retryable errorsTypical candidates:7.28Non-retryable errorsExamples:7.29Timeout doesn't mean failureOne of the most important lessons in integration development:7.30Therefore retries require idempotencyThis is why these belong together:7.31Exponential backoffYou may hear:7.32Limit retriesNever:7.33Retry exhaustionWith Until Successful, after maximum retries are exhausted Mule produces:7.34Retry should usually be narrowGood:7.35codePartial failuresSuppose request contains:7.36Record-level Try patternFor individually processed records:7.37Fail-fast patternSome operations require:7.38Mule cannot magically roll back SalesforceThis is crucial.7.39CompensationExample:7.40Better architecture: async recoveryInstead of:7.41HTTP status mappingAn API should return meaningful status codes.7.42codeHTTP Listener response variablesA common Mule design is:7.43Correlation IDsEvery integration request should ideally be traceable.7.44Don't invent correlation IDs everywhereIf upstream already sends one:7.45codeStructured loggingBad:7.46Don't log secretsNever casually log:7.47Logging the whole payload is often badEasy developer shortcut:7.48A realistic Salesforce error strategySuppose:7.49codeSalesforce validation failureImagine Mule sends:7.50Authentication failuresSuppose Mule's OAuth credential is invalid.7.51Rate limitsSuppose Salesforce says effectively:7.52Error mapping exampleSuppose you call two downstream APIs:7.53Error handling hierarchyThink:7.54Retry hierarchyLikewise:7.55Q&AInterview question: "How do you handle Salesforce outages?"Strong answer:7.56Q&AInterview question: "When use On Error Continue?"“When the error has genuinely been handled and the containing scope can legitimately be considered successful—for example, an optional…7.57Q&A"When use On Error Propagate?"“When I want to log, transform, or classify the error locally but the caller or outer scope still needs to consider the operation failed.”7.58Q&A"When use Try?"“When a specific subset of processors needs local error semantics that differ from the rest of the flow.”7.59Q&A"How do you prevent retry duplicates?"“Use idempotent operations—such as Salesforce upsert against a stable External ID—or maintain an idempotency key/state where the downstream…7.60Q&A"What happens after On Error Continue inside Try?"“The remainder of the Try isn't resumed. The Try is considered successfully handled and processing continues after the Try scope.”7.61Full exampleLet's design our customer integration:7.62But improve it furtherAsk:7.63Developer error-handling checklistWhenever you add an external call, ask:•cheat sheetModule 7 cheat sheetIf you remember just one sentence from this module, use: