wonderful-fetch
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -23,3 +23,3 @@ (function (root, factory) { | ||
var SOURCE = 'library'; | ||
var VERSION = '0.0.3'; | ||
var VERSION = '0.0.4'; | ||
@@ -126,26 +126,31 @@ function WonderfulFetch(url, options) { | ||
} else { | ||
res.text() | ||
.then(function (text) { | ||
if (res.ok) { | ||
if (options.raw) { | ||
return _resolve(res); | ||
} else if (options.json) { | ||
JSON5 = JSON5 || require('json5'); | ||
try { | ||
return _resolve(JSON5.parse(text)); | ||
} catch (e) { | ||
throw new Error(new Error('Response is not JSON: ' + e)) | ||
if (res.ok) { | ||
if (options.raw) { | ||
return _resolve(res); | ||
} else { | ||
res.text() | ||
.then(function (text) { | ||
if (options.json) { | ||
JSON5 = JSON5 || require('json5'); | ||
try { | ||
return _resolve(JSON5.parse(text)); | ||
} catch (e) { | ||
throw new Error(new Error('Response is not JSON: ' + e)) | ||
} | ||
} else { | ||
return _resolve(text); | ||
} | ||
} else { | ||
return _resolve(text); | ||
} | ||
} else { | ||
var error = new Error(text || res.statusText || 'Unknown error'); | ||
Object.assign(error, { status: res.status }) | ||
throw error; | ||
}) | ||
} | ||
}) | ||
.catch(e => { | ||
return _reject(e); | ||
}) | ||
} else { | ||
res.text() | ||
.then(function (text) { | ||
var error = new Error(text || res.statusText || 'Unknown error'); | ||
Object.assign(error, { status: res.status }) | ||
throw error; | ||
}) | ||
.catch(e => { | ||
return _reject(e); | ||
}) | ||
} | ||
} | ||
@@ -152,0 +157,0 @@ }) |
{ | ||
"name": "wonderful-fetch", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "A wrapper around fetch.", | ||
@@ -35,2 +35,2 @@ "main": "./dist/index.js", | ||
"runkitExampleFilename": "examples/process.js" | ||
} | ||
} |
13626
154