Javascript 获取返回类型错误:iPhone 5上的类型错误

Javascript 获取返回类型错误:iPhone 5上的类型错误,javascript,reactjs,fetch,Javascript,Reactjs,Fetch,我在iPhone 5上进行API调用时遇到问题 我在组件内部进行了以下API调用 import FavouritesService from "../../api/FavouritesService"; const Favourites = () => { const getFavs = () => { favouritesService.getFavourites(0, 10, "FULL").then(response => { if (respon

我在iPhone 5上进行API调用时遇到问题

我在组件内部进行了以下API调用

import FavouritesService from "../../api/FavouritesService";
const Favourites = () => {
  const getFavs = () => {
    favouritesService.getFavourites(0, 10, "FULL").then(response => {
      if (response.success === false) {
        //...
      } else {
        //...
      }
    });
  };
};

export default Favourites;
获取api端点并在导入中调用函数的My
FavoriteService
如下所示

import api from "./api";

class FavouriteService {
  getFavourites(page, pageSize, view) {
    return api.get(
      "/api/social-groups?page=" +
        encodeURIComponent(page) +
        "&pageSize=" +
        encodeURIComponent(pageSize) +
        "&view=" +
        encodeURIComponent(view) +
        "&type=FAVOURITE"
    );
  }
}

export default FavouriteService;
我的
api.js
文件(我在其中执行api本身)如下所示

import _ from "lodash";
import "babel-polyfill";
import "isomorphic-fetch";

function handleErrors(response) {
  if (!response.ok) {
    throw Error(response.statusText);
  }
  return response;
}
function handleFetchError(error) {
  // Here is where I get TypeError: Type error
  if (error) {
    return { success: false, error: error };
  }
}

function payloadOptions(method, body) {
  var postBody = body;
  var contentType = "application/x-www-form-urlencoded";
  if (typeof postBody === "object") {
    postBody = JSON.stringify(postBody);
    contentType = "application/json";
  }
  return {
    method: method,
    body: postBody,
    headers: {
      "Content-Type": contentType
    }
  };
}

const defaultOptions = {
  redirect: "error",
  headers: {
    Accept: "application/json"
  }
};

class API {
  request(url, options) {
    return fetch(url, _.defaultsDeep(options || {}, defaultOptions))
      .then(handleErrors)
      .then(response => response.json())
      .catch(handleFetchError);
  }

  get(url, options) {
    return this.request(
      url,
      _.defaultsDeep(options || {}, payloadOptions("GET"))
    );
  }
}

export default new API();
这就是
handleFetchError
中发生错误的地方,
error
返回
TypeError:Type error
。当我
console.log
这个,这就是我所得到的,我无法进一步深入到实际检查这里到底发生了什么

我试着用谷歌搜索这个,但似乎没有其他人有这个特定的问题,所以我假设我在提出这个GET请求的某个步骤出错了


任何帮助都将不胜感激,因为我已经在这方面停留了一段时间。

我发现我必须使用polyfill来提取


这有助于我明白我必须安装
whatwgfetch

我发现我必须使用polyfill才能获取

这帮助我明白了我必须安装
whatwgfetch