Angular $httpProvider

 timeout超時響應

.factory('timestampMarker', ["$rootScope", function () {
    var timestampMarker = {
        'request': function (config) {
            config.timeout = 15000;
            return config;
        }
    };
    return timestampMarker;
}])


.config(['$httpProvider',function ( $httpProvider) {
        //設置調用接口超時
        $httpProvider.interceptors.push('timestampMarker');
}])

設置request和response

.factory('logTimeTaken', [function () {
    var logTimeTaken = {
        request: function (config) {
            config.requestTimestamp = new Date().getTime();
            return config;
        },
        response: function (response) {
            response.config.responseTimestamp = new Date().getTime();
            return response;
        }
    };
    return logTimeTaken;
}])


.config(['$httpProvider',function ( $httpProvider) {
       $httpProvider.interceptors.push('logTimeTaken');
}])
相關文章
相關標籤/搜索