[英]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 显示)
access-control-allow-origin
header param sent by server in the network logs (response headers) and ensure it is correctly configuredaccess-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.