2017-06-16 62 views
0

我有一個返回這個發送錯誤PARAMS到錯誤處理功能

return Upload.http({ 
    url: requestInfo.data.url, 
    method: 'POST', 
    headers: headers, 
    data: file 
}); 

服務。然而,我要趕我是從服務器接收到錯誤,並通過該服務在返回之前解析它,因爲錯誤本身對調用該服務的控制器沒有任何意義。

我嘗試這樣做:

return Upload.http({ 
    url: requestInfo.data.url, 
    method: 'POST', 
    headers: headers, 
    data: file 
}).catch(function(error){ 
    return $q.reject({fileID: requestInfo.data.file.id}); 
}); 

控制器:

file.upload = itemOperationService.uploadItem(uploadInfo, file); 
file.upload.then(
    handleUploadSuccess, 
    handleUploadError, 
    handleUploadProgress); 

它的工作原理。現在錯誤處理函數接收這個對象。但是,使用這種方法,我無法再調用file.upload.abort()函數,因爲它不存在於file.upload對象中。我怎麼能達到我想要的?那可能嗎?

在此先感謝

回答

0

你可以檢查它可以幫助你。

file.upload = itemOperationService.uploadItem(uploadInfo, file); 
file.upload.then(
    function(response) { 
     //handle success respnse here. 
     console.log('get',response) 
    }, 
    function(data) { 
     // Handle error here 
    }); 
+0

這並沒有解決選擇你想傳遞給錯誤處理函數的問題。還是要謝謝你的幫助。 –