Comparing version
{ | ||
"name": "lw-sdk", | ||
"version": "1.3.1", | ||
"version": "1.3.2", | ||
"description": "SDK for Laurel & Wolf API", | ||
@@ -8,3 +8,3 @@ "main": "src/index.js", | ||
"manual-test": "watchify spike/run.js -o spike/bundle.js -v -d", | ||
"test": "npm run lint && browserifyinc --cachefile .tmp/bundle.json test/*.js | tap-closer | smokestack | tap-spec", | ||
"test": "hihat test/*.js -- -p tap-dev-tool", | ||
"test-ci": "zuul -- test/*.js", | ||
@@ -19,7 +19,6 @@ "lint": "lw lint src" | ||
"browserify-incremental": "^3.0.1", | ||
"hihat": "^2.4.1", | ||
"is-promise": "^2.0.0", | ||
"lw-build": "laurelandwolf/build", | ||
"smokestack": "^3.3.0", | ||
"tap-closer": "^1.0.0", | ||
"tap-spec": "^4.0.2", | ||
"tap-dev-tool": "^1.3.0", | ||
"tape": "^4.0.1", | ||
@@ -26,0 +25,0 @@ "zuul": "^3.2.0" |
@@ -1,2 +0,2 @@ | ||
import {omit, merge, pick} from 'lodash'; | ||
import {omit, merge, pick, get as _get} from 'lodash'; | ||
import {Promise} from 'es6-promise'; | ||
@@ -37,3 +37,8 @@ import joinPath from 'join-path'; | ||
else { | ||
response.json().then((body) => { | ||
let contentType = 'json'; | ||
let contentTypeGetter = _get(response, 'headers.get'); | ||
if (contentTypeGetter) { | ||
contentType = response.headers.get('content-type').indexOf('vnd.api+json') > -1 ? 'json' : 'text'; | ||
} | ||
response[contentType]().then((body) => { | ||
@@ -40,0 +45,0 @@ if (response.status < 400) { |
@@ -32,2 +32,8 @@ import {merge, cloneDeep} from 'lodash'; | ||
let body = res.body !== undefined ? res.body : config; | ||
let json = JSONPromise(body); | ||
let text; | ||
if (res.headers && res.headers.get && res.headers.get('content-type').indexOf('text/plain') !== -1) { | ||
json = undefined; | ||
text = JSONPromise(body); | ||
} | ||
@@ -38,3 +44,4 @@ let response = { | ||
headers: res.headers, | ||
json: JSONPromise(body) | ||
json, | ||
text | ||
}; | ||
@@ -41,0 +48,0 @@ |
@@ -114,1 +114,21 @@ import {namespace} from './utils/testing'; | ||
}); | ||
test('non-json responses', ({equal}) => { | ||
let headers = new Headers(); | ||
headers.append("Content-Type", "text/plain"); | ||
mockFetch.restore(); | ||
mockFetch.mock({ | ||
response: { | ||
headers, | ||
body: 'Fail' | ||
} | ||
}); | ||
return request().get().then((res) => { | ||
equal(res.body, 'Fail', 'should parse correctly'); | ||
}); | ||
}); |
257570
0.29%9
-10%6745
0.39%