axios/axios · error · AxiosError
ETIMEDOUT|ECONNABORTED
ETIMEDOUT|ECONNABORTED
Error message
timeout of ${_config.timeout}ms exceeded What it means
Rejected from the XHR adapter's `ontimeout` handler when the request exceeded `config.timeout` milliseconds (set directly on request.timeout at line 41, so the browser enforces it across the whole request lifetime). With the default transitional.clarifyTimeoutError=false the code is ECONNABORTED for backward compatibility; setting clarifyTimeoutError: true yields the more accurate ETIMEDOUT. The message can be overridden with config.timeoutErrorMessage.
Source
Thrown at lib/adapters/xhr.js:166
const err = new AxiosError(msg, AxiosError.ERR_NETWORK, config, request);
// attach the underlying event for consumers who want details
err.event = event || null;
reject(err);
done();
request = null;
};
// Handle timeout
request.ontimeout = function handleTimeout() {
let timeoutErrorMessage = _config.timeout
? 'timeout of ' + _config.timeout + 'ms exceeded'
: 'timeout exceeded';
const transitional = _config.transitional || transitionalDefaults;
if (_config.timeoutErrorMessage) {
timeoutErrorMessage = _config.timeoutErrorMessage;
}
reject(
new AxiosError(
timeoutErrorMessage,
transitional.clarifyTimeoutError ? AxiosError.ETIMEDOUT : AxiosError.ECONNABORTED,
config,
request
)
);
done();
// Clean up request
request = null;
};
// Remove Content-Type if data is undefined
requestData === undefined && requestHeaders.setContentType(null);
// Add headers to the request
if ('setRequestHeader' in request) {
utils.forEach(toByteStringHeaderObject(requestHeaders), function setRequestHeader(val, key) {View on GitHub (pinned to c3f553c740)
Solutions
- Raise config.timeout for the slow endpoint (or set it per-request rather than globally), after confirming the server genuinely needs longer.
- Investigate why the server is slow — the timeout is usually the messenger, not the bug.
- Set transitional: { clarifyTimeoutError: true } so timeouts get code ETIMEDOUT and are distinguishable from aborts in error handling.
- Add retry-with-backoff for idempotent requests that time out intermittently.
- For user-driven cancellation of long requests, prefer AbortSignal.timeout(ms) via the signal option, which composes with other abort reasons.
Example fix
// before
const api = axios.create({ timeout: 3000 });
await api.get('/reports/annual'); // times out, code ECONNABORTED
// after
await api.get('/reports/annual', {
timeout: 30000,
transitional: { clarifyTimeoutError: true }, // rejects with ETIMEDOUT
}); Defensive patterns
Strategy: retry
Validate before calling
const config = { timeout: 10000 };
if (!Number.isFinite(config.timeout) || config.timeout <= 0) {
throw new Error('timeout must be a positive number of milliseconds');
} Type guard
import axios from 'axios';
function isTimeoutError(err) {
return axios.isAxiosError(err) &&
(err.code === 'ETIMEDOUT' || err.code === 'ECONNABORTED') &&
/timeout/i.test(err.message);
} Try / catch
try {
await axios.get(url, { timeout: 10000 });
} catch (err) {
if (axios.isAxiosError(err) && (err.code === 'ETIMEDOUT' || err.code === 'ECONNABORTED')) {
// slow server/network: retry idempotent requests with a longer timeout or backoff
} else {
throw err;
}
} Prevention
- Set an explicit timeout sized from real p99 latency of the endpoint — the default of 0 means axios waits forever.
- Check both ETIMEDOUT and ECONNABORTED when detecting timeouts; older axios versions used ECONNABORTED unless transitional.clarifyTimeoutError is enabled.
- Set transitional: { clarifyTimeoutError: true } to get the unambiguous ETIMEDOUT code.
- Retry timeouts only for idempotent requests, with backoff — the server may still have processed the original.
- Set per-request timeouts for known-slow endpoints instead of one instance-wide value.
When it happens
Trigger: axios.get(url, {timeout: 5000}) where the server takes longer than 5s to fully respond; large uploads/downloads on slow links exceeding the timeout (XHR timeout covers the entire exchange, not just time-to-first-byte); an instance created with a small default timeout applied to a slow endpoint.
Common situations: A global axios.create({timeout: 3000}) instance later used for slow report/export endpoints; cold-start latency on serverless backends; timeouts appearing only in production due to network distance; confusing the ECONNABORTED code with an abort — check whether the message says 'timeout of Nms exceeded' to tell them apart.
Related errors
AI-assisted analysis of axios/axios@c3f553c740 (2026-07-31).
Data as JSON: /data/errors/704eb693575d4b7b.json.
Report an issue: GitHub.