Skip to content

Latest commit

 

History

History
76 lines (51 loc) · 3.53 KB

validate-status-code-policy.md

File metadata and controls

76 lines (51 loc) · 3.53 KB
title description services author ms.service ms.topic ms.date ms.author
Azure API Management policy reference - validate-status-code | Microsoft Docs
Reference for the validate-status-code policy available for use in Azure API Management. Provides policy usage, settings, and examples.
api-management
dlepow
azure-api-management
reference
07/23/2024
danlep

Validate status code

[!INCLUDE api-management-availability-all-tiers]

The validate-status-code policy validates the HTTP status codes in responses against the API schema. This policy may be used to prevent leakage of backend errors, which can contain stack traces.

[!INCLUDE api-management-validation-policy-schema-size-note]

[!INCLUDE api-management-policy-form-alert]

Policy statement

<validate-status-code unspecified-status-code-action="ignore | prevent | detect" errors-variable-name="variable name">
    <status-code code="HTTP status code number" action="ignore | prevent | detect" />
</validate-status-code>

Attributes

Attribute Description Required Default
unspecified-status-code-action Action to perform for HTTP status codes in responses that aren’t specified in the API schema. Policy expressions are allowed. Yes N/A
errors-variable-name Name of the variable in context.Variables to log validation errors to. Policy expressions aren't allowed. No N/A

Elements

Name Description Required
status-code Add one or more elements for HTTP status codes to override the default validation action for status codes in responses. No

status-code attributes

Attribute Description Required Default
code HTTP status code to override validation action for. Yes N/A
action Action to perform for the matching status code, which isn’t specified in the API schema. If the status code is specified in the API schema, this override doesn’t take effect. Yes N/A

[!INCLUDE api-management-validation-policy-actions]

Usage

Usage notes

  • This policy can only be used once in a policy section.

[!INCLUDE api-management-validation-policy-common]

Example

<validate-status-code unspecified-status-code-action="prevent" errors-variable-name="responseStatusCodeValidation" />

[!INCLUDE api-management-validation-policy-error-reference]

Related policies

[!INCLUDE api-management-policy-ref-next-steps]