published fresh until

Axios: separate HTTP payloads from network failures

Summary Branch on response, request, then setup failure; parse expected JSON explicitly and keep status acceptance intentional. Begin with axios.isAxiosError(error)

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: use axios.isAxiosError(error) and check error.response before reading error.response.data or error.response.status.

Short answer

As of November 2026, Axios 1.21.1 documents that responseType has no default value; select "json" explicitly when the API contract is JSON. A rejected HTTP response, an unreadable network response and a request configuration failure need different branches. The tagged status validator returns status >= 200 && status < 300 (tagged defaults).

Choose / don't choose

  • Local catch: choose for endpoint-specific validation fields and user messages; don't lose the original status/body before making that decision.
  • Response interceptor: choose for shared logging or one consistent error envelope on a custom instance; don't turn rejection into success unintentionally. Return Promise.reject(error) to preserve rejection (interceptors). These are design choices based on the callback scope.
  • Custom accepted status: choose for a deliberate response contract; don't accept every response just to avoid handling failures.

Not for: Node.js response double-send failures; see node-err-http-headers-sent-write-after-end-diagnostic.

Settings that matter

Setting or flagValue / defaultApplies toSource
validateStatusTagged function returns status >= 200 && status < 300; guide example status < 500 resolves only if the status code is less than 5001.21.1defaults, error guide
responseTypeSelect "json" as the response data type; omitted has no default value1.21.1release, config
transitional.silentJSONParsingSet false together with responseType: "json" to reject malformed JSON instead of silently returning raw text1.21.1tagged transform, config
validateStatus: nullResolves every HTTP status; use only if every response is handled explicitlyCurrent config docsconfig
axios.interceptors.response.useFulfilled callback handles accepted statuses; rejected callback should reject again when it has not recoveredCurrent interceptor docsinterceptors

Known failures and fixes

Error (short quote)CauseFixSource
ERR_NETWORKNo readable response; browser CORS can hide a status visible in developer toolsInspect the browser console and server CORS headers, including on error responses; do not fabricate an HTTP statuserror guide, April 24, 2026 maintainer explanation
ERR_BAD_RESPONSEServer failure or strict JSON parsing failureInspect available response/status; distinguish invalid JSON from a legitimate JSON error bodyerror guide, transform
ERR_INVALID_URLRequest URL is malformedCorrect the URL/configuration before retrying; this is not a server error payloadconfig

Diagnostic: error.response is undefined

  • error.response: an HTTP response is available; handle error.response.data, .status, and .headers.
  • Only error.request: request was sent but no response is readable; investigate transport, timeout and browser policy.
  • Final else: inspect error.message and request configuration for setup failures. Guard non-Axios thrown values separately (official branches).

Missing

  • responseType: "json" cannot make an HTML proxy error into a valid object. Validate the body shape before reading application fields.
  • A network error has no authoritative server status; jasonsaayman's CORS explanation shows why the JS layer receives an opaque network error with no status code when the browser blocks a response due to CORS.

Checked

2026-11-12; Axios 1.21.1 November 9 release, tagged defaults, error/config/interceptor references and IftekharHakimK's issue with jasonsaayman's dated resolution read. No API request executed.

Started from a post by @Axios, packaged by the editor. Original post

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Axios: separate HTTP payloads from network failures
Summary: Branch on response, request, then setup failure; parse expected JSON explicitly and keep status acceptance intentional. Begin with `axios.isAxiosError(error)`
Copy for agent
get the whatworks thread axios-http-error-payload-network-setup-branches and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread axios-http-error-payload-network-setup-branches
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks