Angular 避免控制台跟踪 $http 错误 [英] Angular avoid Console trace on $http error

查看:25
本文介绍了Angular 避免控制台跟踪 $http 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我使用 REST api 来获取我的数据.如果发送这样的请求

In my application I am using a REST api to get my data. If a send a request like this

$http.get('api/entity/' + $scope.entityId).success(/* DO STUFF */).error(/* DO STUFF */)

在服务中,如果 entityId 不存在,我将返回 404.在错误函数中,我使用状态(第二个参数)捕获它并以适当的方式对其进行操作.

In the service, if the entityId does not exist I return a 404. In the error function I catch it using the status (second parameter) and act on it in a proper way.

我对 angular 抛出异常并污染 javascript 控制台这一事实感到恼火.它似乎发生在 Angular.js:8165

I'm being annoyed by the fact that angular if throwing an exception and pollutes the javascript console. It seem to happen on Angular.js:8165

有什么方法可以告诉 angular 我是一个成熟的开发人员,我会以一种很好的方式自己处理他认为的错误吗?

It there any way to tell angular that I'm a grown up developer and I will handle what he sees as an error myself in a nice way?

换句话说,我可以告诉 angular 不要输出那些废话吗?

In other words, can I tell angular to not output that crap?

谢谢,

推荐答案

这是浏览器的功能,而不是进行日志记录的 AngularJS 的一部分.以下是此页面控制台的示例:

This is your browser's functionality, and not a part of AngularJS that does the logging. Here's a sample from the console of this page:

您可以看到它记录了与您在问题评论中链接的完全相同的错误消息,并且确实是 指向源代码中的一部分,但我没有添加任何日志记录.

You can see it logs the exact same error message as you linked in the question's comment, and is indeed pointing to a part in the source code, but I didn't add any logging statements.

你能做的最好的事情是关注这个答案并向控制台添加一个过滤器.

The best thing you can do is follow this answer and add a filter to the console.

这篇关于Angular 避免控制台跟踪 $http 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆