Fetch: TypeMismatchedError on Edge

Created on 7 Sep 2016  路  10Comments  路  Source: github/fetch

I am running my website with Edge on Window 10. Here is the code the produce the TypeMismatchedError, code: 17

return new Promise((resolve, reject) => {
    return fetch('/api/search/trips', {
      method: 'POST',
      headers: {
        "x-access-token": "example-key",
        'Accept': 'application/json',
        'Content-Type': 'application/json; charset=utf-8'
      },
      body: JSON.stringify(searchData)
    })
    .then(response => response.json())
    .then(json => resolve(json))
    .catch(err => reject(err))
  })

This code throws TypeMismatched exception before any request could be fired. I write it with Webpack.

It works fine in other Chrome, Firefox and Safari.
Do you have any idea ?

Most helpful comment

I have the exact same problem. But I guess the answer is does not have to be on this repo but rather around here
https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8546263/

All 10 comments

Try running the fetch call from within Edge's web console to isolate the code without other dependencies like Webpack.

This handler needs to detect if the request returned a successful response before consuming the JSON response body.

.then(response => response.json())

should be something like this

.then(response => {
  if (response.ok) {
    return response.json()
  } else {
    // HTTP status code not in 200-299 success range
    // Could be 401, 404, 500, etc.
  }
})

Fetch only invokes the catch handler in cases where a Response cannot be created, like network failures, for example. If the HTTP request and response cycle succeeded, the then handler is invoked, even if the HTTP status code is a failure.

Edge has a native implementation of window.fetch and does not use this polyfill code, so I'll close out this issue.

It even doesn't fire any request, just throw error. The funny thing is that code works in the console. But not from my redux actions. I think Webpack has done something wrong with fetch.

I have the exact same problem. But I guess the answer is does not have to be on this repo but rather around here
https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8546263/

In order to workaround this issue, I managed to use superagent instead of fetch

(I'm on the Edge team.) We attemped to reproduce this bug and were unable (using Edge 14.14393) . Here is my reproducible test case; please extend as necessary in order to reproduce the bug: https://gist.github.com/nolanlawson/54d29e82036bed5410adf9767d8cc64a

Thanks @nolanlawson for keeping an eye on this!

Perhaps it was the same cause as #409, which is a bug marked "fixed" in Edge.

Thanks @nolanlawson

I have looked at your gist.

There is no issue when I use fetch directly on browser, but issue happens when I use webpack and import fetch into my app to make request.

I found this closed issue when investigating a bug with a Edge + fetch that resulted in a TypeMismatchedError.

For me everything worked fine until there was a non-ascii character in the payload, such as the "茅" in "Math茅matiques".

In @nolanlawson 's test case, if I change

  body: JSON.stringify({foo: 'bar'})

to

  body: JSON.stringify({foo: 'b茅r'})

then it fails.

This SO issue explains the workaround I used: https://stackoverflow.com/questions/39419250/fetch-api-doesnt-work-with-non-english-characters-in-microsoft-edge

I also ran into the issue where the fetch wasn't even showing in the network tab and console reported a TypeMismatchError.

This was specifically happening to me on the production build of my application but not when it was in dev mode.

What fixed it for me was setting babel-polyfill before whatwg-fetch in the webpack config's entry:

const entry = [
  'babel-polyfill',
  'whatwg-fetch',
  PATHS.app,
]
Was this page helpful?
0 / 5 - 0 ratings

Related issues

AllenFang picture AllenFang  路  5Comments

seekcx picture seekcx  路  4Comments

codeashian picture codeashian  路  3Comments

huanghaiyang picture huanghaiyang  路  3Comments

shirotech picture shirotech  路  3Comments