You work as an API Developer for MDFT Pro, a well-known training agency that delivers certification courses to students worldwide. Mark, the Integration Services Manager, has deployed a REST web service that manages course enrollments and student registrations. The service is accessed through an Azure API Management instance that provides rate limiting, authentication, and policy enforcement. During testing, you discovered that when two trainers attempt to enroll the same student in a course simultaneously, the backend service doesn’t properly handle the conflict scenario. Instead of returning the correct HTTP 409 (Conflict) status code, the service returns a generic HTTP 500 (Internal Server Error) with only the word “conflict” in the response body. Students and trainers see confusing error messages, and monitoring systems can’t properly track conflict errors versus actual server failures. You need to configure an API Management policy in the on-error section that detects this specific error condition and transforms it into the correct HTTP response.
How should you complete the policy to ensure conflicts produce the correct HTTP 409 status code?
<on-error>
<base />
<choose>
<when condition="@(context.Response.StatusCode == 500 && context.LastError.Message.Contains("conflict"))">
<return-response>
<__________ code="409" reason="conflict" />
</return-response>
</when>
<otherwise />
</choose>
</on-error>
Choose the correct answer from the options below.
Explanations for each answer: