我正在向服务发出get请求以检查某个密钥是否存在 – 如果是,它返回一些数据,如果没有,则返回401.我无法控制服务 – 但我不想在控制台中显示401 – 这似乎是不专业的,因为在大多数情况下,此密钥将不存在.有没有办法捕捉401所以它永远不会打印到控制台?
现在我有以下内容 – 我可以测试状态是否为401,但我无法捕捉到它阻止它打印到控制台.这可能吗?我不想在401s上使用全局处理程序,我只想为这个特定请求捕获一个.
$http.get(url,{ withCredentials: true }) .success(function(data,status,headers,config) { result.resolve(data,config); }) .error(function(data,config) { if(status === 401) { // I can test for a 401 here,but that doesn't seem to help } result.reject(data); });