2015-10-12 40 views
0

我正在使用Restangular攔截器來處理狀態代碼爲412,409等錯誤。 但我沒有在requestInterceptor函數中獲取狀態。 我已經使用Typescript聲明瞭Restangular RequestInterceptor。Restangular Error Interceptor中的意外令牌ü

在我app.ts文件,

app.run(Restangular){  
    Restangular.setErrorInterceptor(function(response) {//code to handle error}); 
      } 

錯誤: enter image description here

回答

2

Restangular提供了一個選項,以獲得一個完整的響應訪問,可能設立這個可能的幫助。通過使用Restangular.setFullResponse(true),您應該能夠訪問攔截器中的狀態碼。

所以,我根據你的代碼片段猜現在看起來是這樣的(因爲有你在哪裏注射Restangular,如果您有任何其他配置部分,其在設定應該去)

app.run(Restangular){ 
    Restangular.setFullResponse(true);  
    Restangular.setErrorInterceptor(function(response) {//code to handle error}); 
      } 

這一點很重要要指出的是,設置這個選項,現在訪問你的回答將是你所有的服務,除非你創造的東西來處理下一個.data行爲悅目不同:

function(response){ 
var result = response.data; 
var statusCode = result.status; 
var responseData = result.myApiResponse; 
} 

欲瞭解更多信息,PL輕鬆檢查:https://github.com/mgonto/restangular#setfullresponse,並希望我的帖子有所幫助。