Custom 413 Payload Error Handling in Apigee Edge
I’m working on a scenario where the client sends requests with payloads exceeding 10 MB. The client has specifically requested a custom error response instead of Apigee’s default 413 Payload Too Large message.
We attempted to implement this by using a RaiseFault policy with a conditional check to return a custom JSON error payload. However, during testing, we observed that the API call is rejected immediately—before reaching the authorization or any flow logic. It appears that Apigee Edge is blocking the request at the entry point due to the payload size, and the flow doesn’t proceed far enough to trigger our custom logic.
Question:
Is it possible to configure Apigee Edge to return a custom response for 413 Payload Too Large errors?
Hello @NishVOIS
Have you explicitly verified through Apigee debug that the request does not reach your underlying proxying logic?
I am wondering if you have the Fault Rule out of scope, something as follows should work (this is for a Default Fault rule but can be conditionalized given use case, but would verify the above assumption):
<DefaultFaultRule name="DefaultFaultRule">
<Step>
<Condition>(fault.name = "TooBigBody")</Condition>
<Name>AM-MyCustomError</Name>
</Step>
<AlwaysEnforce>true</AlwaysEnforce>
</DefaultFaultRule>
Thank for the help ,
Addition of condition in default rule worked.
Only thing is we have to always enforce true.
Hi, thanks for your help earlier. I need one more clarification.
We have configured the above condition in our API, but the issue is that the default request body size limit is currently set to 100 MB, and the request is failing only when it reaches 100 MB instead of 10 MB. We want the request to fail once the body exceeds 10 MB.
Could you please advise how we can implement this logic in the API? We have tried several steps as per the documentation, but it hasn’t resolved the issue.
Hello @NishVOIS There should be a header you can extract called “Content-Length” (assuming the request isn’t chunked) that should contain the size of the request. From there, you can add validation as per payload size (if greater then or less then 10 MB) and call into your fault rule accordingly
Best
Matt