Closed
Description
I think it would be good if you could provide some default config for $http in the DSHttpAdapter.
So you can add stuff like interceptors if you want to handle certain errors etc, for example that the user is not authenticated with the api.
I was thinking about these changes to the DSHttpAdapterProvider
var defaults = this.defaults = {
/**
* @doc property
* @id DSHttpAdapterProvider.properties:defaults.queryTransform
* @name defaults.queryTransform
* @description
* Transform the angular-data query to something your server understands. You might just do this on the server instead.
*
* @param {string} resourceName The name of the resource.
* @param {object} params Params sent through from `$http()`.
* @returns {*} Returns `params` as-is.
*/
queryTransform: function(resourceName, params) {
return params;
},
httpConfig: {}
};
function HTTP(config) {
var start = new Date().getTime();
config = DSUtils.deepMixIn(this.defaults.httpConfig, config);
return $http(config).then(function(data) {
$log.debug(data.config.method + ' request:' + data.config.url + ' Time taken: ' + (new Date().getTime() - start) + 'ms', arguments);
return data;
});
}
Then one could add config to all $http requests that angular-data executes
DSHttpAdapter.defaults.httpConfig = {
interceptor: /* ... */
};
The reason for not just configuring $http globally would be if you wanted to do other $http requests to other sources that is not your API