Axios Payload Exceeds Server Limit Behavior

When sending data with the Axios HTTP client, exceeding payload size limits results in distinct behaviors depending on whether the limitation is enforced by the client runtime or the destination server. If the payload surpasses the client's internal threshold, Axios halts the request locally and throws an error. If the data reaches the server but exceeds server-configured constraints, the server terminates processing and typically responds with an HTTP 413 (Payload Too Large) status code or abruptly drops the connection, causing Axios to reject the request promise.

Client-Side vs. Server-Side Enforcement

Handling large payloads involves two distinct enforcement layers:

  1. Client-Side Restrictions (Node.js): In Node.js environments, Axios enforces default size limits through maxBodyLength and maxContentLength (default is 10 MB). If your payload exceeds this threshold, Axios throws a client-side error before the network request is fully dispatched:
    AxiosError: Request body larger than maxBodyLength limit
  2. Server-Side Restrictions: In browser environments or when Node.js client limits are raised, the full payload travels to the server. If the payload size exceeds limits set by intermediate proxies (like Nginx) or backend frameworks (like Express or Spring), the server takes over error handling.

Server Behavior and Axios Responses

When a server receives a payload exceeding its configured threshold, it typically responds in one of two ways:

1. HTTP 413 (Payload Too Large)

The standard server behavior is returning an HTTP status code 413 Payload Too Large (formerly Request Entity Too Large).

When Axios receives a 413 response:

2. Immediate Connection Termination (ECONNRESET)

To prevent Denial of Service (DoS) attacks and conserve bandwidth, some web servers and reverse proxies close the TCP socket immediately without waiting to read the rest of the stream or sending an HTTP response body.

When this occurs:

How to Resolve Payload Size Errors

Resolving payload size issues requires adjusting configurations on both the client and the server.

Configure Axios

To prevent Axios from blocking large uploads in Node.js, set maxBodyLength and maxContentLength to Infinity:

const axios = require('axios');

axios.post('https://example.com/api/upload', largeData, {
  maxContentLength: Infinity,
  maxBodyLength: Infinity
});

Configure the Server and Reverse Proxy

Ensure that all intermediary services are configured to accept the larger payload size: