简体   繁体   English

Angular 6和AWS-放大通用网络错误

[英]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.

相关问题 aws-amplify js 到 angular 应用程序有错误:未定义全局 - aws-amplify js to angular app has error: global is not defined aws-amplify AWSIoTProvider 不是具有 Angular 8 的构造函数 - aws-amplify AWSIoTProvider is not a constructor with Angular 8 放大“npm install --save aws-amplify @aws-amplify/ui-angular”破坏了代码 - Amplify "npm install --save aws-amplify @aws-amplify/ui-angular" breaks the code angular 与 aws-amplify for google 注册的集成问题 - Integration issue in angular with aws-amplify for google sign up aws-放大错误!!! 类型错误:无法读取 null 的属性“indexOf” - aws-amplify error !!! TypeError: Cannot read property 'indexOf' of null 如何在 Angular 11 和“@aws-amplify/ui-angular”中删除“amplify-authenticator 不是已知元素” - How to remove "amplify-authenticator is not a known element" in Angular 11 and '@aws-amplify/ui-angular' AWS-Amplify,如何在角度登录后重定向到另一个 URL? - AWS-Amplify, How do I redirect to another URL after sign-in in angular? 将 Angular 应用程序更新到最新版本 10.0 后出现 aws-amplify 警告 - aws-amplify warning after updating angular application to the latest version 10.0 使用 AWS Amplify 构建 Angular 10 应用程序时出错 - Error in building Angular 10 app with AWS Amplify AWS Amplify Ionic 5 Angular 10 构建错误 - AWS Amplify Ionic 5 Angular 10 build error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM