简体   繁体   English

错误代码:0 ExceptionMessage:Http 失败响应(未知 url):0 Angular 5 中的未知错误

[英]Error Code: 0 ExceptionMessage: Http failure response for (unknown url): 0 Unknown Error in Angular 5

I am getting this error "Error Code: 0 ExceptionMessage: Http failure response for (unknown URL): 0 Unknown Error" on my Angular 5 project.我在我的 Angular 5 项目中收到此错误“错误代码:0 ExceptionMessage:Http 失败响应(未知 URL):0 未知错误”。

However, I am not able to recreate this issue, I saw this repeated issue on the Rollbar error log.但是,我无法重新创建此问题,我在 Rollbar 错误日志中看到了此重复问题。 I tried the same steps on my local machine, also tried to recreate in different browsers like chrome, safari, etc but no luck.我在本地机器上尝试了相同的步骤,还尝试在不同的浏览器(如 chrome、safari 等)中重新创建,但没有运气。

I'm using AWS lambda with .NET core 2.1, API proxy gateway, and Angular 5 on FrontEnd.我正在使用 AWS lambda 和 .NET 核心 2.1、API 代理网关和 ZC31C335EF37283C1Z51B1 上的 Front8.

AngularJs code AngularJs代码

getOrgPublicAssetName(id: number): Observable<any> {
    let content = this.appSharedService.getSitecontents();
    if (content !== '')
      return Observable.of(content);
    if (id !== undefined)
      return <Observable<any>>(
        this.httpClient
          .get(this.organizationUrl + '/SiteContent/' + id)
          .map(result => {
            this.appSharedService.setsitecontents(result);
            return result;
          })
          .pipe(catchError(this.exceptionService.catchBadResponse))
      );
    else return Observable.of();
  }

Following is my startup.cs configure function where I am already using cors.以下是我的 startup.cs 配置 function,我已经在使用 cors。

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            app.UseXRay("Organizations");
            app.UseMiddleware(typeof(ErrorHandlingMiddleware));

            Environment.SetEnvironmentVariable(EnvironmentVariableAWSRegion.ENVIRONMENT_VARIABLE_REGION, Configuration["AWS:Region"]);

            // Create a logging provider based on the configuration information passed through the appsettings.json
            // You can even provide your custom formatting.
            loggerFactory.AddLambdaLogger(Configuration.GetLambdaLoggerOptions());

            //Enable swagger endpoint if the environment is not production

            if (!IsProductionEnvironment)
            {
                // Enable middleware to serve generated Swagger as a JSON endpoint.
                app.UseSwagger();

                // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), specifying the Swagger JSON endpoint.
                app.UseSwaggerUI(c =>
                {
                    if (env.EnvironmentName == "Local")
                        c.SwaggerEndpoint(SwaggerLocalEndpoint, ApiName);
                    else
                        c.SwaggerEndpoint(SwaggerEndpoint, ApiName);
                });
            }

            app.UseCors(policy =>
            {
                //TODO: This has to be addressed once we deploy both api and ui under the same domain
                policy.AllowAnyOrigin();
                policy.AllowAnyHeader();
                policy.AllowAnyMethod();
                policy.WithExposedHeaders("WWW-Authenticate");
                policy.WithExposedHeaders("X-Total-Count");
            });
            app.UseAuthentication();
            app.UseMvc(routeBuilder =>
            {
                routeBuilder.Count().Filter().OrderBy().Expand().Select().MaxTop(null);
                routeBuilder.MapODataServiceRoute("odata", "odata", OrganizationModelBuilder.GetEdmModel());
            });
            app.UseForwardedHeaders(new ForwardedHeadersOptions
            {
                ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
            });
            app.UseResponseCaching();
        }
    }

Your browser is not allowing your code to read the HTTP response because of the CORS error.由于 CORS 错误,您的浏览器不允许您的代码读取 HTTP 响应。

You will see the error in browser console logs (Chrome shows it)您将在浏览器控制台日志中看到错误(Chrome 显示)

  1. Check AWS ApiGateway if OPTIONS request is correctly handled如果正确处理了 OPTIONS 请求,请检查 AWS ApiGateway
  2. In the Network TAB (if you are using Chrome), check the pre-flight request在网络选项卡中(如果您使用的是 Chrome),检查飞行前请求
  3. You must check access-control-allow-origin header param sent by server in the network logs (response headers) and ensure it is correctly configured您必须检查服务器在网络日志(响应标头)中发送的access-control-allow-origin header 参数并确保其配置正确

If nothing works, delete the API gateway configuration and recreate them (it would be easy if you have cloud formation scripts).如果没有任何效果,请删除 API 网关配置并重新创建它们(如果您有云形成脚本会很容易)。 It always works它总是有效

响应标头

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 针对(未知网址)的Http错误响应:0未知错误-仅在Angular 5上 - Http failure response for (unknown url): 0 Unknown Error - Only on Angular 5 Angular + NET Core “(未知 url)的 Http 失败响应:0 未知错误” - Angular + NET Core "Http failure response for (unknown url): 0 Unknown Error" (未知网址)的Http失败响应:0 Angular 5上的未知错误 - Http failure response for (unknown url): 0 Unknown Error on Angular 5 “(未知 url)的 Http 失败响应:0 未知错误” Angular - “Http failure response for (unknown url): 0 Unknown Error” Angular Angular 4:“(未知 URL)的 Http 失败响应:0 未知错误” - Angular 4: "Http failure response for (unknown URL): 0 Unknown Error" 针对(未知网址)的Http错误响应:0未知错误 - Http failure response for (unknown url): 0 Unknown Error “针对(未知URL):0未知错误的Http故障响应”, - “Http failure response for (unknown url): 0 Unknown Error”, 边缘浏览器问题:(url)0角度的未知错误的http故障响应 - Edge browser issue: http failure response for (url) 0 unknown error in angular Angular + Expressjs Http 失败响应未知错误 0 - Angular + Expressjs Http failure response Unknown error 0 我在 Angular 中收到“(未知 url)的 Http 失败响应:0 未知错误”而不是实际错误消息 - I get "Http failure response for (unknown url): 0 Unknown Error" instead of actual error message in Angular
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM