2016-08-18 31 views
0

我想在超時發生之前返回緩存響應,然後更新緩存。是否有可能通過請求攔截器做出假響應?

我嘗試這樣做:

.factory('TestInterceptor', TestInterceptor); 

function TestInterceptor($q) { 
    return { 
     request: request, 
     response: response 
    }; 

    function request(config) { 
     ... 
     return $q.resolve(fakeResponse); 
     ... 
    } 
    function response() { 
    .... 
    } 
} 

,但它不工作。

回答

1

這是不可能的。 As the manual says

請求:攔截器被一個http配置對象調用。該功能可以自由修改配置對象或創建一個新的配置對象。該函數需要直接返回配置對象,或者包含配置或新配置對象的承諾。

相關問題