Angular 角度6和aws放大了一般网络误差
我有一个angular 6和aws amplify/aws amplify angular应用程序,我正在开发,目前我正在尝试进行HTTP GET。我收到了一条通用的Angular 角度6和aws放大了一般网络误差,angular,amazon-web-services,aws-mobilehub,aws-amplify,Angular,Amazon Web Services,Aws Mobilehub,Aws Amplify,我有一个angular 6和aws amplify/aws amplify angular应用程序,我正在开发,目前我正在尝试进行HTTP GET。我收到了一条通用的错误:网络错误消息,我读到的消息可能是从身份验证到与amazon的通信问题 我的函数看起来是这样的,我试图简单地将lambda的响应记录到控制台 async getOwnerDecks() { const authToken = await Auth.currentSession().then(data => {
错误:网络错误消息,我读到的消息可能是从身份验证到与amazon的通信问题
我的函数看起来是这样的,我试图简单地将lambda的响应记录到控制台
async getOwnerDecks() {
const authToken = await Auth.currentSession().then(data => {
return data.idToken.jwtToken;
});
const authHeader = {
Authorization: authToken
};
this.result = await this.amplifyService.api().get('decks', '', {headers: authHeader}).then( resp => {
return resp;
}).catch(err => {
console.log(err);
});
}
就这样。我可以通过Postman从awsmobileawsmobile云api invoke decks get/decks
调用,并获得成功的响应,但是从上面的函数中我什么也得不到。我尝试过使用API.get和angularService.API().get,但都失败了
Error
columnNumber: 15
config: Object { timeout: 0, xsrfCookieName: "XSRF-TOKEN", xsrfHeaderName: "X-XSRF-TOKEN", … }
fileName: "http://localhost:8080/vendor.js"
lineNumber: 96651
message: "Network Error"
request: XMLHttpRequest { __zone_symbol__xhrSync: false, __zone_symbol__xhrURL: "https://xxxxxx.execute-api.eu-west-1.amazonaws.com/MobileHub_Deployments/decks", __zone_symbol__ON_PROPERTYreadystatechange: handleLoad(), … }
response: undefined
stack: "createError@http://localhost:8080/vendor.js:96651:15\nhandleError@http://localhost:8080/vendor.js:96194:14\nwrapFn@http://localhost:8080/polyfills.js:3510:30\n./node_modules/zone.js/dist/zone.js/</ZoneDelegate.prototype.invokeTask@http://localhost:8080/polyfills.js:2743:17\nonInvokeTask@http://localhost:8080/vendor.js:40796:24\n./node_modules/zone.js/dist/zone.js/</ZoneDelegate.prototype.invokeTask@http://localhost:8080/polyfills.js:2742:17\n./node_modules/zone.js/dist/zone.js/</Zone.prototype.runTask@http://localhost:8080/polyfills.js:2510:28\n./node_modules/zone.js/dist/zone.js/</ZoneTask.invokeTask@http://localhost:8080/polyfills.js:2818:24\ninvokeTask@http://localhost:8080/polyfills.js:3862:9\nglobalZoneAwareCallback@http://localhost:8080 /polyfills
我使用的是最新版本6 angular/cli、aws amplify和aws amplify angular npm软件包
我已经验证了它与cors无关,因为我以前遇到过cors头问题,现在在我将所需头添加到awsmobile lambda之后,错误就消失了
有什么明显的遗漏吗?您有以下代码:
this.result = await this.amplifyService.api().get('decks', '', {headers: authHeader}).then( resp => {
return resp;
}).catch(err => {
console.log(err);
});
看起来您正在.get参数中传递一个空路径。如果你有这样的东西
this.result = await this.amplifyService.api().get('decks', '/decks', {headers: authHeader}).then( resp => {
return resp;
}).catch(err => {
console.log(err);
});
…其中传递的是/decks路径而不是空字符串
this.result = await this.amplifyService.api().get('decks', '/decks', {headers: authHeader}).then( resp => {
return resp;
}).catch(err => {
console.log(err);
});