Set status code
The
set-status
policy sets the HTTP status code to the specified value.XML
<set-status code="" reason=""/>
This example shows how to return a 401 response if the authorization token is invalid.
XML
<choose>
<when condition="@(context.variables.tokenstate.body.active == false)">
<return-response response-variable-name="existing response variable">
<set-status code="401" reason="Unauthorized" />
<set-header name="WWW-Authenticate" exists-action="override">
<value>Bearer error="invalid_token"</value>
</set-header>
</return-response>
</when>
</choose>
Element | Description | Required |
set-status | Root element | Yes |
Attribute | Description | Required | Default |
code="integer" | The HTTP status code to return. | Yes | N/A |
reason="string" | A description of the reason for returning the status code. | Yes | N/A |
This policy can be used in the inbound, outbound, and on-error policy scopes.
Questions?
We're always happy to help with any issues you might have!
Send us an email to [email protected] or request the demo with our sales team!
Last modified 3yr ago