Skip to content

Commit cf0a08c

Browse files
committed
Fixes #18. Fixes #27.
Stable Version 2.1.1
1 parent 029d283 commit cf0a08c

8 files changed

+33
-17
lines changed

CHANGELOG.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
##### 2.1.0 - xx September 2015
1+
##### 2.1.1 - 20 September 2015
2+
3+
###### Backwards compatible bug fixes
4+
- #18 - Cannot read property 'http' of undefined
5+
- #27 - logResponse doesn't reject when this.http() rejects with something that is not an Error
6+
7+
##### 2.1.0 - 11 September 2015
28

39
###### Backwards compatible API changes
410
- #20 - DSHttpAdapter.POST does not pick DSHttpAdapter.defaults.basePath

Gruntfile.js

+1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ module.exports = function (grunt) {
152152
});
153153

154154
grunt.registerTask('test', ['build', 'karma:ci', 'karma:min']);
155+
grunt.registerTask('test_c9', ['build', 'karma:c9']);
155156
grunt.registerTask('build', [
156157
'clean',
157158
'standard',

dist/js-data-http.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
* js-data-http
3-
* @version 2.1.0 - Homepage <http://www.js-data.io/docs/dshttpadapter>
3+
* @version 2.1.1 - Homepage <http://www.js-data.io/docs/dshttpadapter>
44
* @author Jason Dobry <[email protected]>
55
* @copyright (c) 2014-2015 Jason Dobry
66
* @license MIT <https://github.com/js-data/js-data-http/blob/master/LICENSE>
@@ -127,6 +127,7 @@ return /******/ (function(modules) { // webpackBootstrap
127127
function DSHttpAdapter(options) {
128128
_classCallCheck(this, DSHttpAdapter);
129129

130+
options = options || {};
130131
this.defaults = new Defaults();
131132
if (console) {
132133
this.defaults.log = function (a, b) {
@@ -234,7 +235,8 @@ return /******/ (function(modules) { // webpackBootstrap
234235
}
235236

236237
// logs the HTTP response
237-
function logResponse(data) {
238+
function logResponse(data, isRejection) {
239+
data = data || {};
238240
// examine the data object
239241
if (data instanceof Error) {
240242
// log the Error object
@@ -243,7 +245,7 @@ return /******/ (function(modules) { // webpackBootstrap
243245
} else if (typeof data === 'object') {
244246
var str = start.toUTCString() + ' - ' + config.method + ' ' + config.url + ' - ' + data.status + ' ' + (new Date().getTime() - start.getTime()) + 'ms';
245247

246-
if (data.status >= 200 && data.status < 300) {
248+
if (data.status >= 200 && data.status < 300 && !isRejection) {
247249
if (_this.defaults.log) {
248250
_this.defaults.log(str, data);
249251
}
@@ -265,7 +267,9 @@ return /******/ (function(modules) { // webpackBootstrap
265267
throw new Error('You have not configured this adapter with an http library!');
266268
}
267269

268-
return this.http(config).then(logResponse, logResponse);
270+
return this.http(config).then(logResponse, function (data) {
271+
return logResponse(data, true);
272+
});
269273
}
270274
}, {
271275
key: 'GET',

dist/js-data-http.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js-data-http.min.map

+1-1
Large diffs are not rendered by default.

package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "js-data-http",
33
"description": "http adapter for js-data.",
4-
"version": "2.1.0",
4+
"version": "2.1.1",
55
"homepage": "http://www.js-data.io/docs/dshttpadapter",
66
"repository": {
77
"type": "git",
@@ -27,8 +27,8 @@
2727
"http"
2828
],
2929
"devDependencies": {
30-
"babel-core": "5.8.24",
31-
"babel-eslint": "^4.1.1",
30+
"babel-core": "5.8.25",
31+
"babel-eslint": "4.1.3",
3232
"babel-loader": "5.3.2",
3333
"es6-promise": "3.0.2",
3434
"grunt": "0.4.5",
@@ -50,9 +50,9 @@
5050
"karma-script-launcher": "0.1.0",
5151
"karma-sinon": "1.0.4",
5252
"karma-spec-reporter": "0.0.20",
53-
"standard": "^5.2.2",
53+
"standard": "5.3.1",
5454
"time-grunt": "1.2.1",
55-
"webpack-dev-server": "1.10.1"
55+
"webpack-dev-server": "1.11.0"
5656
},
5757
"standard": {
5858
"parser": "babel-eslint"

src/index.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ defaultsPrototype.verbsUseBasePath = false
3838

3939
class DSHttpAdapter {
4040
constructor (options) {
41+
options = options || {}
4142
this.defaults = new Defaults()
4243
if (console) {
4344
this.defaults.log = (a, b) => console[typeof console.info === 'function' ? 'info' : 'log'](a, b)
@@ -132,7 +133,8 @@ class DSHttpAdapter {
132133
}
133134

134135
// logs the HTTP response
135-
function logResponse (data) {
136+
function logResponse (data, isRejection) {
137+
data = data || {}
136138
// examine the data object
137139
if (data instanceof Error) {
138140
// log the Error object
@@ -141,7 +143,7 @@ class DSHttpAdapter {
141143
} else if (typeof data === 'object') {
142144
let str = `${start.toUTCString()} - ${config.method} ${config.url} - ${data.status} ${(new Date().getTime() - start.getTime())}ms`
143145

144-
if (data.status >= 200 && data.status < 300) {
146+
if (data.status >= 200 && data.status < 300 && !isRejection) {
145147
if (_this.defaults.log) {
146148
_this.defaults.log(str, data)
147149
}
@@ -163,7 +165,9 @@ class DSHttpAdapter {
163165
throw new Error('You have not configured this adapter with an http library!')
164166
}
165167

166-
return this.http(config).then(logResponse, logResponse)
168+
return this.http(config).then(logResponse, function (data) {
169+
return logResponse(data, true)
170+
})
167171
}
168172

169173
GET (url, config) {

test/find.spec.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ describe('DSHttpAdapter.find(resourceConfig, id, options)', function () {
8686
return dsHttpAdapter.find(Post, 1).then(function () {
8787
throw new Error('Should not have succeeded!');
8888
}, function () {
89+
console.log(loggedError);
8990
assert.isString(loggedError);
90-
assert.isTrue(loggedError.indexOf('api/posts/1') !== -1);
91+
assert.isTrue(loggedError.indexOf('api/posts/1') !== -1, loggedError);
9192
});
9293
});
9394

0 commit comments

Comments
 (0)