Comparing version 0.6.0 to 0.7.0
{ | ||
"name": "fitch", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"description": "A lightweight Promise based HTTP client, using Fetch API.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -5,3 +5,3 @@  | ||
[](https://badge.fury.io/js/fitch) | ||
[](https://www.npmjs.com/package/fitch) | ||
[](https://travis-ci.org/raphaelpor/fitch.js) | ||
@@ -8,0 +8,0 @@ [](https://github.com/raphaelpor/fitch.js/blob/master/docs/Intro.md) |
@@ -33,19 +33,23 @@ require('es6-promise').polyfill(); | ||
} | ||
const configObj = config.create(method, req); | ||
const call = fetch(url + paramsEncoded, configObj); | ||
return req.raw ? call : call.then(this.check); | ||
return req.raw ? call : call.then(resp => this.check(resp, req.dataType)); | ||
}, | ||
check(resp) { | ||
if (resp.ok) { | ||
return resp.json(); | ||
check(resp, dataType = 'json') { | ||
const typeList = ['arrayBuffer', 'blob', 'formData', 'json', 'text']; | ||
const included = typeList.indexOf(dataType); | ||
if (resp.ok && included !== -1) { | ||
return resp[dataType](); | ||
} | ||
throw new Error(`${resp.status} - ${resp.statusText}.`); | ||
}, | ||
error(err) { | ||
if (err) { | ||
console.log('Error >', err); | ||
} | ||
error(err = '') { | ||
console.log('Error >', err); | ||
}, | ||
}; |
32734
15