-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
90 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/** | ||
* @author Jason Dobry <[email protected]> | ||
* @file js-data-http.js | ||
* @version 1.0.0-alpha.1 - Homepage <http://www.js-data.iojs-data-http/> | ||
* @version 1.0.0-alpha.2 - Homepage <http://www.js-data.iojs-data-http/> | ||
* @copyright (c) 2014 Jason Dobry | ||
* @license MIT <https://github.com/js-data/js-data-http/blob/master/LICENSE> | ||
* | ||
|
@@ -1418,8 +1418,13 @@ defaultsPrototype.forceTrailingSlash = ''; | |
|
||
defaultsPrototype.httpConfig = {}; | ||
|
||
defaultsPrototype.log = console ? function (a, b, c, d, e) { | ||
console.log(a, b, c, d, e); | ||
defaultsPrototype.log = console ? function (a, b) { | ||
console[typeof console.info === 'function' ? 'info' : 'log'](a, b); | ||
} : function () { | ||
}; | ||
|
||
defaultsPrototype.error = console ? function (a, b) { | ||
console[typeof console.error === 'function' ? 'error' : 'log'](a, b); | ||
} : function () { | ||
}; | ||
|
||
|
@@ -1448,17 +1453,28 @@ dsHttpAdapterPrototype.getAllPath = function (resourceConfig, options) { | |
|
||
dsHttpAdapterPrototype.HTTP = function (config) { | ||
var _this = this; | ||
var start = new Date().getTime(); | ||
var start = new Date(); | ||
config = deepMixIn(config, _this.defaults.httpConfig); | ||
if (_this.defaults.forceTrailingSlash && config.url[config.url.length] !== '/') { | ||
config.url += '/'; | ||
} | ||
return http(config).then(function (data) { | ||
if (_this.defaults.log) { | ||
_this.defaults.log(data.config.method.toUpperCase() + ' request: ' + data.config.url + ' Time taken: ' + (new Date().getTime() - start) + 'ms', data); | ||
|
||
function logResponse(data) { | ||
var str = start.toUTCString() + ' - ' + data.config.method.toUpperCase() + ' ' + data.config.url + ' - ' + data.status + ' ' + (new Date().getTime() - start.getTime()) + 'ms'; | ||
if (data.status >= 200 && data.status < 300) { | ||
if (_this.defaults.log) { | ||
_this.defaults.log(str, data); | ||
} | ||
return data; | ||
} else { | ||
if (_this.defaults.error) { | ||
_this.defaults.error('FAILED: ' + str, data); | ||
} | ||
throw data; | ||
} | ||
return data; | ||
}); | ||
} | ||
|
||
return http(config).then(logResponse, logResponse); | ||
}; | ||
|
||
dsHttpAdapterPrototype.GET = function (url, config) { | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters