fitch
Version:
A lightweight Promise based HTTP client, using Fetch API.
28 lines (22 loc) • 716 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
function check(resp) {
var dataType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'json';
var typeList = ['arrayBuffer', 'blob', 'formData', 'json', 'text'];
var included = typeList.indexOf(dataType) !== -1;
if (resp.ok && included) {
return resp[dataType]().then(function (data) {
return {
data: data,
status: resp.status,
statusText: resp.statusText,
headers: resp.headers
};
});
}
var errorMerssage = !included ? 'Invalid data type' : resp.status + ' - ' + resp.statusText + '.';
throw new Error(errorMerssage);
}
exports.default = check;