[英]Angular 6 and aws-amplify generic network error
I have an angular 6 and aws-amplify/aws-amplify-angular app I am working on and current I am trying to do a HTTP GET. 我有一个正在使用的angular 6和aws-amplify / aws-amplify-angular应用程序,当前正在尝试执行HTTP GET。 I am getting a generic Error: Network Error
message which I have read can really be anything from auth to communication problems with amazon. 我收到一个通用Error: Network Error
我已阅读的Error: Network Error
消息实际上可能是从身份验证到与亚马逊的通信问题的任何内容。
My function looks like this and I am trying to simply log to the console the response from my lambda. 我的函数看起来像这样,我试图将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);
});
}
And that is it. 就是这样。 I can invoke via Postman, via this command from awsmobile awsmobile cloud-api invoke decks get /decks
and get successful responses but from the function above I get nothing. 我可以通过邮递员通过awsmobile的此命令进行调用awsmobile cloud-api invoke decks get /decks
并获得成功的响应,但是从上面的函数中我什么也没得到。 I have tried using API.get and angularService.api().get and all fail. 我尝试使用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
Here are the response I should get 这是我应该得到的回应
{
requestBody: null,
pathParams: '/decks',
queryStringParams: null,
headerParams:
{ Accept: 'application/json, text/plain, */*',
'CloudFront-Forwarded-Proto': 'https',
'CloudFront-Is-Desktop-Viewer': 'true',
'CloudFront-Is-Mobile-Viewer': 'false',
'CloudFront-Is-SmartTV-Viewer': 'false',
'CloudFront-Is-Tablet-Viewer': 'false',
'CloudFront-Viewer-Country': 'ES',
Host: 'xxxxxxxxxxxxx.execute-api.eu-west-1.amazonaws.com',
'User-Agent': 'axios/0.17.1',
Via: '1.1 xxxxxxxxxxxxxxx.cloudfront.net (CloudFront)',
'X-Amz-Cf-Id': 'iNPucPQXZybc7Zg1AfA005rE-W30Qs-TG1V2pDK5fDHAPWSNSBg==',
'x-amz-date': '20180620T143059Z',
'X-Amzn-Trace-Id': 'Root=1-5b2a6523-3c88e3d2f77853e8cbf4351c',
'X-Forwarded-For': 'xxx.xxx.xxx.xxx,xxx.xxx.xxx.xxx',
'X-Forwarded-Port': '443',
'X-Forwarded-Proto': 'https' },
stage: 'Development',
stageVariables: { stage: 'Development' },
cognitoIdentityId: null,
httpMethod: 'GET',
sourceIp: 'xxx.xxx.xxx.xxx',
userAgent: 'axios/0.17.1',
requestId: '8cec8ff3-7496-11e8-a737-9d1996926e66',
resourcePath: '/decks'
}
I am using the latest version 6 angular/cli, aws-amplify and aws-amplify-angular npm packages. 我正在使用最新的版本6 angular / cli,aws-amplify和aws-amplify-angular npm软件包。
I have verified it is not cors related, as I was getting a cors header issue before and now the error has gone away once I added the required headers to the awsmobile lambda. 我已经验证了它与cors不相关,因为以前我遇到过cors标头问题,现在,一旦将所需的标头添加到awsmobile lambda中,该错误就消失了。
Anything obvious I am missing? 有什么明显的我想念的吗?
You have the following code: 您有以下代码:
this.result = await this.amplifyService.api().get('decks', '', {headers: authHeader}).then( resp => {
return resp;
}).catch(err => {
console.log(err);
});
It looks like you are passing in an empty path in the .get parameters. 看起来您在.get参数中传递了空路径。 Should you have something like this... 你应该有这样的东西吗?
this.result = await this.amplifyService.api().get('decks', '/decks', {headers: authHeader}).then( resp => {
return resp;
}).catch(err => {
console.log(err);
});
...in which the /decks path is being passed instead of an empty string? ...在哪个/ decks路径而不是空字符串中传递?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.