【发布时间】:2015-05-21 18:43:28
【问题描述】:
我正在向服务发出 get 请求以检查是否存在某个键 - 如果存在,它会返回一些数据,如果不存在,它会返回 401。我无法控制服务 - 但我可以不想在控制台中显示 401 - 这似乎不专业,因为在大多数情况下,此键不存在。有没有办法捕获 401,使其永远不会打印到控制台?
现在我有以下内容 - 我可以测试状态是否为 401,但我无法捕获它以防止它打印到控制台。这可能吗?我不想在 401 上使用全局处理程序,我只想为这个特定请求捕获一个。
$http.get(url, { withCredentials: true })
.success(function(data, status, headers, config) {
result.resolve(data, status, headers, config);
})
.error(function(data, status, headers, config) {
if(status === 401)
{
// I can test for a 401 here, but that doesn't seem to help
}
result.reject(data);
});
【问题讨论】:
-
你不能。错误的请求错误由您的浏览器处理,角度异常处理程序也不会这样做。
标签: angularjs get http-status-code-401