apicase-adapter-fetch
Advanced tools
Comparing version 0.2.1 to 0.2.2
36
index.js
@@ -19,4 +19,30 @@ var pathToRegexp = require('path-to-regexp') | ||
return fetch(ctx.payload.url, ctx.payload.options) | ||
.then(ctx.resolve) | ||
.catch(ctx.reject) | ||
.then(function(res) { | ||
return res[ctx.payload.parser]().then(function (data) { | ||
ctx.resolve({ | ||
success: ctx.payload.validateStatus(res.status), | ||
data: response.body, | ||
error: null, | ||
status: res.status, | ||
statusText: res.statusText | ||
}) | ||
}).catch(function (error) { | ||
ctx.reject({ | ||
success: false, | ||
data: response.body, | ||
error: error, | ||
status: res.status, | ||
statusText: res.statusText | ||
}) | ||
}) | ||
}) | ||
.catch(function (error) { | ||
ctx.reject({ | ||
success: false, | ||
data: null, | ||
error: error, | ||
status: null, | ||
statusText: null | ||
}) | ||
) | ||
}, | ||
@@ -26,2 +52,8 @@ convert(payload) { | ||
url: compilePath(payload.url, payload.params || {}), | ||
parser: payload.parser || 'json', | ||
validateStatus: | ||
payload.validateStatus || | ||
function(status) { | ||
return status >= 200 && status < 300 | ||
}, | ||
options: { | ||
@@ -28,0 +60,0 @@ method: payload.method || 'GET', |
{ | ||
"name": "apicase-adapter-fetch", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "Fetch adapter for Apicase", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
40700
82