We have a REST API running in App Services. The API receives large files along with some other data. We are performing validations in our Rest API and returning Bad Request if any validations fail. We are seeing that APIM is waiting for the entire request to be received before it returns the Bad Request response to the user. Is there a way to configure APIM to return immediately when the backend returns an error and not wait until the entire request is received.
Asked
Active
Viewed 305 times
1 Answers
0
We have something which is called as Mock-response which aborts the operations when mentioned status code appears, this is used to log the error response and also when the request get successed.
These are from Error handing in API Management policies, basically we have inbound, outbound, backend, and on-error policies.
Definition from MS Docs:
Mock response can be added in on-error, below is the sample for all the policies:
<policies>
<inbound>
<!-- statements to be applied to the request go here -->
</inbound>
<backend>
<!-- statements to be applied before the request is
forwarded to the backend service go here -->
</backend>
<outbound>
<!-- statements to be applied to the response go here -->
</outbound>
<on-error>
<!-- statements to be applied if there is an error
condition go here -->
</on-error>
</policies>
Policy statement for mock-response as below:
<mock-response status-code="code" content-type="media type"/>
Sample:
<mock-response status-code='200' content-type='application/json'/>

SaiKarri-MT
- 1,174
- 1
- 3
- 8
-
Thank you for the response. I tried what you described and the response still does not come back until the APIM receives the entire file. If I upload a 60 MB file it takes about 20 seconds to respond. If I hit app services directly it comes back immediately. Application insights is very help to see the full chain of events. – JBL Nov 10 '21 at 12:19
-
@JBL Check for mock response and configure it accordingly to return if any error occurs, in the answer I mentioned as the sample status code as 200 which means success. Similarly set up for your own error code. And yes Applications Insights were helpful for this process. – SaiKarri-MT Nov 22 '21 at 07:54