2017-03-17 77 views
2

我正在使用AWS API網關,並且正在使用角度2代碼向我的API進行調用,問題在於會話令牌過期並且我的UI代碼嘗試使用它 - API網關會拋出403錯誤,指出「請求中包含的安全令牌已過期」。這是我在控制檯 - 網絡部分中可以看到的內容。無法獲得映射到角度2代碼的正確http響應

現在,這403錯誤是夾在無極碼=> catch處理程序,我試圖表明該消息是由服務器發送即

{"message":"The security token included in the request is expired"} 

這裏的問題 - 我無法顯示正確的控制檯和Sweet Alert Box中的錯誤消息。

在調試Catch處理程序接收到的錯誤對象時,會顯示此Json - 實際錯誤對象不在那裏。

{"data":"","status":0,"statusText":"","headers":{},"config":{"method":"GET","headers":{"x-api-key":"<api-key>","Accept":"application/json","x-amz-date":"201705957Z","Authorization":"AWS4-HM256 Credential=ASIAJ66A/20170317/us-west-1/execute-api/aws4_request, SignedHeaders=accept;host;x-amz-date;x-api-key, Signature=59a2bce53fc3fc25a0dcc36c80243ae63","x-amz-security-token":"<security-token>","Content-Type":"application/json"},"timeout":0,"transformRequest":[null],"transformResponse":[null],"url":"https://api.tech.in/adviser/Suraj","data":""}} 

我能夠解決這個錯誤400由API網關發送錯誤提供錯誤paswsord或用戶名。

注意:CORS已啓用&映射響應和集成有403錯誤映射錯誤顯示標題有CORS。

怎麼辦 - 來解決這個問題 - 因爲陷入catch處理最後的錯誤對象不正確的HTTP響應數據

這裏是我的代碼

// this is the final Consumer of the Promise 
this.http.getFundDetailedList() //*** 
     .then(response => this.fundDetailsList = response.data.Items) 
     .catch(err => { 
     swal('Error Reported', "Please login again \n"+err.data, 'error'); 
     console.log(this.handleError(err)); 
     }); 
    } 

    // helper function for Error Handling 
private handleError(error: Response | any) { 
    let errMsg: string; 
    console.log('Error Json '+ JSON.stringify(error)); // Wrong Error Object shown in console 
    if (error instanceof Response) { 
     const body = error.json() || ''; 
     const err = body.error || JSON.stringify(body); 
     errMsg = `${error.status} - ${error.statusText || ''} ${err}`; 
    } else { 
     errMsg = error.message ? error.message : JSON.stringify(error.data.message); 
    } 
    return errMsg; 
    } 


    // Calls AWS API - coded inside a http service class 
    getFundDetailedList() { 
    return this.credentialService.getAwsSDK().adviserFundsGet({ 'adviser': this.credentialService.$id }, {}, {}); 
    } 
+0

什麼是安全令牌? –

+0

你可以添加http調用的代碼嗎? – Akkusativobjekt

+0

安全令牌被刪除了一半 - 它被AWS Securiy和所有使用,...上傳我的代碼在一分鐘 –

回答

2

CORS標頭不發送正確地用於API網關中的驗證失敗。這是一個已知的問題,您可以在AWS論壇上找到更多細節

https://forums.aws.amazon.com/thread.jspa?messageID=671237&#720951

從本質上講,與某些類型的錯誤(認證失敗/錯誤的請求/ API密鑰認證/問題調用集成)的頭映射是這意味着CORS頭文件不會在響應中返回。

給您帶來的不便,我們深表歉意。但我們正在積極努力解決這個問題。

+0

Thanx的澄清...及其更新此帖子的請求與估計日期得到此錯誤修復。這對其他觀衆也是有幫助的。 –

相關問題