Salesforce Certified MuleSoft Developer free question 2 / 10 · Domain 10: Handling Errors
A flow calls an external API with an HTTP Request. The API answers 404 and Mule raises HTTP:NOT_FOUND. The On Error Continue of the flow must store the number 404 itself in a variable, not the text of the error. Which expression returns that number?
- #[error.errorType]
- #[error.cause]
- #[error.errorMessage.attributes.statusCode]
- #[error.description]
Show the answer and explanation
Answer: C
Why this is correct
The Mule error object has several fields, and the page lists the selector for each one with the HTTP:NOT_FOUND example. The description is a sentence, the type is HTTP:NOT_FOUND, and the cause is the underlying Java Throwable. The status code lives in the error message. The errorMessage field becomes available when a connector or component exposes the message it has interpreted as an error, such as an HTTP request that receives a status code Mule treats as an error. You can then reach the payload of that message with error.errorMessage.payload and its attributes with error.errorMessage.attributes. For an HTTP request that returns an error, the page says you can use error.errorMessage.attributes.statusCode to select the value of the status code, such as 404.
Why the other options are wrong
"#[error.errorType]" … error.errorType returns the type of the error, here HTTP:NOT_FOUND. That is a type name made of a namespace and an identifier, not the numeric status code.
"#[error.description]" … error.description returns the sentence that describes the problem, for example that the GET on the resource failed because it was not found (404). It is text and is not the number alone.
"#[error.cause]" … error.cause returns the underlying Java Throwable. For a failed request it prints a human readable description of the exception, not the status code as a value you can select.
Attributes carry the status
The failed response travels inside the error as a normal Mule message, so its attributes are available like any other attributes. DataSense in Studio can show them, and that makes it easy to find statusCode, the reason phrase and the headers of the response that caused the error.