How can I stop my proxy from forwarding a request on to the target endpoint if the request doesn't match on one of the proxy endpoints? I'd like it to return a 404 response.
Solved! Go to Solution.
You can include a default flow that doesn't have any condition and add a raise fault policy to the default flow to return the HTTP 404 error response
<Flows> <Flow name="ApiRoutesGet"> <Description /> <Request> <Step> <FaultRules /> </Step> </Request> <Response /> <Condition>(proxy.pathsuffix MatchesPath "/api/routes") and (request.verb = "GET")</Condition> </Flow> <Flow name="UnknownResource"> <Description /> <Request> <Step> <FaultRules /> <Name>Unknown-Resource</Name> </Step> </Request> <Response /> </Flow> </Flows>
<RaiseFault async="false" continueOnError="false" enabled="true" name="Unknown-Resource"> <DisplayName>Unknown-Resource</DisplayName> <FaultRules /> <Properties /> <FaultResponse> <Set> <Headers /> <Payload contentType="application/json">{"error":{ "code": "404", "message": "Unknown Resource" }}</Payload> <StatusCode>404</StatusCode> <ReasonPhrase>Not Found</ReasonPhrase> </Set> </FaultResponse> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> </RaiseFault>
You can include a default flow that doesn't have any condition and add a raise fault policy to the default flow to return the HTTP 404 error response
<Flows> <Flow name="ApiRoutesGet"> <Description /> <Request> <Step> <FaultRules /> </Step> </Request> <Response /> <Condition>(proxy.pathsuffix MatchesPath "/api/routes") and (request.verb = "GET")</Condition> </Flow> <Flow name="UnknownResource"> <Description /> <Request> <Step> <FaultRules /> <Name>Unknown-Resource</Name> </Step> </Request> <Response /> </Flow> </Flows>
<RaiseFault async="false" continueOnError="false" enabled="true" name="Unknown-Resource"> <DisplayName>Unknown-Resource</DisplayName> <FaultRules /> <Properties /> <FaultResponse> <Set> <Headers /> <Payload contentType="application/json">{"error":{ "code": "404", "message": "Unknown Resource" }}</Payload> <StatusCode>404</StatusCode> <ReasonPhrase>Not Found</ReasonPhrase> </Set> </FaultResponse> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> </RaiseFault>
User | Count |
---|---|
3 | |
2 | |
1 | |
1 | |
1 |