import featch from "isomorphic-fetch";

const fakingURL = "http://jsonplaceholder.typicode.com";
const getAllUsers = `${fakingURL}/users`;

function toJSON(featchP) {
  return featchP.then(checkStatus).then(parseJSON).catch(error => {
    console.log("request failed", error);
  });
}

function checkStatus(response) {
  if (response.status >= 200 && response.status < 300) {
    return response;
  } else if (response.headers.get("content-type") === "application/json") {
    const error = new Error("content-type error,is not a json");
    error.response = response;
    throw error;
  } else {
    const error = new Error(response.statusText);
    error.response = response;
    throw error;
  }
}

function parseJSON(response) {
  return response.json();
}

export const getUsers = () => toJSON(featch(getAllUsers));

@@ -2,17 +2,16 @@
 mport fe
-a
 tch from
@@ -55,16 +55,17 @@
  = %22http
+s
 ://jsonp
@@ -151,17 +151,16 @@
 oJSON(fe
-a
 tchP) %7B%0A
@@ -170,17 +170,16 @@
 eturn fe
-a
 tchP.the
@@ -792,17 +792,16 @@
 oJSON(fe
-a
 tch(getA

更新 example