Skip to content

Commit

Permalink
add check status reponse to fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
loverajoel committed Oct 19, 2015
1 parent 665ae8d commit 1eef5b1
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,26 @@ class Client {
_body = JSON.stringify(body);
}

let checkStatus = (response) => {
if (response.status >= 200 && response.status < 300) {
return response;
} else {
var error = new Error(response.statusText);
error.response = response;
throw error;
}
}

let parseJSON = (response) => {
return response.json();
}

return fetch(_url, {
method: method || 'GET',
headers: _headers,
body: _body
}).then((response) => {
return response.json();
});
}).then(checkStatus)
.then(parseJSON)
};
}

Expand Down

0 comments on commit 1eef5b1

Please sign in to comment.