Hi,
In your example you don't have a ROUTE assertion so httpRouting.reasonCode will always be NULL.
What we do is to have 'error.code' and 'error.msg' variables.
We use them in Customize Error Response assertion.
Then dealing wih ROUTE assertions:

Here when ROUTE fails, it will call the 'Error" bloc and our 'Sanofi Routing' encap will handle the httpRouting.reasonCode and convert it if needed, filling-in 'status' variable and 'error.msg'. error.code is then set to this status and the Stop processing will "call" the Custom Error Response
For other error checking:

If any one of Int1 or Int2, it will call the Error bloc. if error.code already set (in Int1 or Int2 blocs), it will just fail and call 'Custom Error Response', otherwise it will default an error code and msg, and fails.
After this, we also export error.code and error.msg to be used on 'custom-message-completed' policy, where we export metrics to Splunk.
So to sum up things, our "real" variable to handle response code is error.code.
Original Message:
Sent: Apr 10, 2025 08:58 PM
From: Jon Schendt
Subject: Capturing Error Response Status Codes
I'm wondering how to best capture response status codes for custom error responses.
For instance, if I use the Customize Error Response Assertion, and set the response status to 404 in the assertion, I don't see that value in the ${response.http.status} variable. If I were to return a template response rather than an error, I would see the response status in that variable.
A little policy to demonstrate:

The status shows up in the browser, so it has to be somewhere, but I also see that ${response} doesn't have any information.
If best practice is to have another context variable to reference the response code and then reference that in the custom error response assertion, that's fine, but maybe someone knows where the variable is set, and if it can be referenced.