我构建了angular 4和asp.net项目。 我试图找出为什么我仍然在控制台中看到错误,即使我做错误处理。 当我插入数据库中不存在的名称时,这是我在控制台中遇到的错误。
GET http://localhost:53842/api/queriestest/asdasdas 500 (Internal Server Error)
组件中的过滤功能
filter(name: string) {
console.log(name);
this.serviceQueries.filterQueries(name)
.subscribe(
(data: Response) => {
this.listQueries = data.json();
},
(error: AppError) => {
if (error instanceof BadInputError) {
alert('this post has already has been deleted')
}
else {
alert('An unexpected error occured');
}
}
);
ServicesQueries.ts(BadInputError和AppError是我自己构建的类)
filterQueries(name: string) {
console.log(`my name is ${name}`);
return this.http.get('http://localhost:53842/api/queriestest/' + name)
.catch((error: Response) => {
console.log("ee");
if (error.status === 500) {
return Observable.throw(new BadInputError(error.json()));
}
return Observable.throw(new AppError(error.json()));
});
}
QueriesTestController.ts
[HttpGet("{name}")]
public IActionResult filterPerson(string name)
{
List<Employee> ilIst = new List<Employee>();
Employee Emp;
Emp = _context.Employee.Where(x => x.EmployeeName == name).First();
ilIst.Add(Emp);
return Json(ilIst);
}
我的问题是为什么我仍然在控制台中看到错误,我不希望以这种方式向用户显示,即使我处理它。那是为什么?
答案 0 :(得分:0)
这是您浏览器的功能,
如果您使用的是Chrome,则可以直接从浏览器中禁用日志,但是如果没有添加新功能,则无法阻止显示错误消息。