Skip to content

JavaScript and API errorAxiosError: “Network Error” (ERR_NETWORK)

A request made with Axios fails with AxiosError: Network Error and code ERR_NETWORK, and error.response is undefined, so there is no status code to go on. The request left your code, but no readable response came back. The browser or the device blocked it or could not reach the server.

Short answer

Open the browser’s Network tab and console: a CORS message there means the API must send Access-Control-Allow-Origin for your site. If your page is on HTTPS and the API URL starts with http://, the browser blocks it as mixed content: use HTTPS for the API. On a phone or emulator, localhost is the device itself, so use your computer’s LAN address (or 10.0.2.2 on the Android emulator) and allow cleartext only for development. Also check the API URL and that the server is running and reachable.

Why there is no response, and the fix

  1. 01

    CORS blocked the response

    “The request was made but no response was received” Axios, Handling errors

    The most common cause in the browser. The server answered, but without the CORS headers for your origin, so the browser hides the response and Axios only sees a network error. The console shows the real CORS message. Fix it on the server, not in the Axios call.

    // Express API
    import cors from 'cors';
    app.use(cors({ origin: ['https://app.example.com'] }));
  2. 02

    An http:// API from an https:// page

    “Mixed content requests are insecure requests for resources from a secure context” MDN, Mixed content: examples

    A site served over HTTPS cannot call an http:// API: browsers block it as mixed content. It works locally, because browsers treat http://localhost as secure, and fails once deployed. Put the API behind HTTPS and update the base URL.

    const api = axios.create({
      baseURL: 'https://api.example.com', // not http://
    });
  3. 03

    localhost from a phone, emulator or container

    In React Native, Expo or Docker, localhost means the device or container itself, not your computer. Use your computer’s LAN IP address, 10.0.2.2 on the Android emulator, or the service name in Docker Compose. Android blocks plain http:// by default and iOS App Transport Security does too, so use HTTPS or allow cleartext for development builds only.

    // Android emulator
    const api = axios.create({ baseURL: 'http://10.0.2.2:3000' });
  4. 04

    Tell network errors apart from HTTP errors

    When the server answers with 4xx or 5xx, Axios fills error.response. Only when there is no response at all do you get Network Error. Log both cases separately so the next failure points at the right cause.

    try {
      await api.get('/me');
    } catch (err) {
      if (err.response) console.error('HTTP', err.response.status, err.response.data);
      else if (err.request) console.error('No response:', err.code, err.config?.url);
      else console.error('Setup error:', err.message);
    }

Checked against the vendor’s docs on : Axios docs: Handling errors; MDN: Mixed content.

Rather hand it over?

Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.

Related: “Blocked by CORS policy” · “TypeError: Failed to fetch” · ECONNREFUSED: connection refused

Questions

More on this error

Why does it work in Postman but not in the browser?

Postman does not enforce CORS or mixed-content rules; browsers do. If a request works in Postman and fails with Network Error in the browser, look at CORS headers and http versus https first.

Can I fix CORS from the Axios side?

No. Headers such as Access-Control-Allow-Origin must come from the server. Adding them to the request does nothing, and it can trigger an extra preflight request.

Can you fix it for me?

If one bug is the whole problem, the App Fix Ticket covers it: a written diagnosis first, then the fix. If the app has more going on, the Launch Check is a written check of the whole app. Each issue found is rated critical, high, medium or low, with where it is and how it was confirmed. No issues worth fixing, no charge. If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way. This applies to the first 10 Launch Checks bought after October 30, 2026.

A different error?

Describe it and get a written quote

Send the error and what you were doing. You get a written scope, a fixed price and a timeline; Simon replies by email, usually within one business day.