Repository: axios/axios (js)

Issue:
`fetch` adapter: handling of network errors different from `xhr`
### Describe the bug

Hello! First up: thank you for the work to include a fetch adapter in axios, this is fantastic ❤️ 

I noticed a (potential) issue, or at least a difference in behaviour, when switching adapters around the production of ERR_NETWORK. 

Glancing at the fetch adapters code, it looks like the issue comes from the `if (err.name === 'NetworkError') {` check, which works with XHR but fetch rejects with a `TypeError` with `Failed to fetch` as the message. It might just be a matter of swapping the strings, in which case that's straight forward.

What I wasn't sure about, is how wide that "Failed to fetch" scope is (MDN only describes the exception _class_), and whether it overlaps with any of the [other error types that are listed](https://github.com/axios/axios/blob/v1.x/README.md#error-types). MDN documents a [number of failure modes for this TypeError](https://developer.mozilla.org/en-US/docs/Web/API/fetch#exceptions), which may complicate things.

Happy to help/open a PR when needed, though I'd like to iron out the uncertainty around the error modes first

### To Reproduce

https://github.com/glsignal/scratch-axios-network-error or https://codesandbox.io/p/github/glsignal/scratch-axios-network-error/main

### Code snippet

```js
import { beforeAll, afterAll, describe, expect, it } from "vitest";

import { http, HttpResponse } from "msw";
import { setupServer } from "msw/node";

import axios, { AxiosError } from "axios";

const server = setupServer();

beforeAll(() => {
  server.listen();
});

afterAll(() => {
  server.close();
});

describe("error events", () => {
  async function buildNetworkError(adapter) {
    server.use(http.get("/test", () => HttpResponse.error()));

    try {
      return await axios.get("http://localhost/test", { adapter });
    } catch (event) {
      return event;
    }
  }

  describe("using xhr adapter", () => {
    it("indicates that it is a network error", async () => {
      const error = await buildNetworkError("xhr");

      expect(error.code).toEqual(AxiosError.ERR_NETWORK);
    });
  });

  describe("using fetch adapter", () => {
    it("indicates that it is a network error", async () => {
      const error = await buildNetworkError("fetch");

      expect(error.code).toEqual(AxiosError.ERR_NETWORK);
    });
  });
});
```


### Expected behavior

I'd expect `error.code` to equal `AxiosError.ERR_NETWORK` with both adapters.

### Axios Version

1.7.0-beta.0

### Adapter Version

fetch

### Browser

_No response_

### Browser Version

_No response_

### Node.js Version

_No response_

### OS

_No response_

### Additional Library Versions

_No response_

### Additional context/Screenshots

_No response_

Pull request:
fix(fetch): treat TypeError: fetch failed as an AxiosError.ERR_NETWORK error;
Fixes #6374 

Patch:
diff --git a/lib/adapters/fetch.js b/lib/adapters/fetch.js
index c569982..a25b717 100644
--- a/lib/adapters/fetch.js
+++ b/lib/adapters/fetch.js
@@ -196,13 +196,16 @@ export default isFetchSupported && (async (config) => {
   } catch (err) {
     onFinish();
 
-    let {code} = err;
-
-    if (err.name === 'NetworkError') {
-      code = AxiosError.ERR_NETWORK;
+    if (err && err.name === 'TypeError' && /fetch/i.test(err.message)) {
+      throw Object.assign(
+        new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request),
+        {
+          cause: err.cause || err
+        }
+      )
     }
 
-    throw AxiosError.from(err, code, config, request);
+    throw AxiosError.from(err, err && err.code, config, request);
   }
 });
 


Test patch:
diff --git a/test/unit/adapters/fetch.js b/test/unit/adapters/fetch.js
index c47e210..1d8498e 100644
--- a/test/unit/adapters/fetch.js
+++ b/test/unit/adapters/fetch.js
@@ -370,4 +370,14 @@ describe('supports fetch with nodejs', function () {
 
     assert.strictEqual(data, '/?test=1&foo=1&bar=2');
   });
+
+  it('should handle fetch failed error as an AxiosError with ERR_NETWORK code', async () => {
+    try{
+      await fetchAxios('http://notExistsUrl.in.nowhere');
+      assert.fail('should fail');
+    } catch (err) {
+      assert.strictEqual(String(err), 'AxiosError: Network Error');
+      assert.strictEqual(err.cause && err.cause.code, 'ENOTFOUND');
+    }
+  });
 });