简体   繁体   English

如何在angularjs HTTP请求中隐藏错误消息?

[英]How to hide error message in angularjs http request?

I have get a request from an API, some times I would get the EXIF information, but sometimes I will get error message {"error":"no exif data"} How can I hide this error message. 我从API获得请求,有时会获得EXIF信息,但有时会收到错误消息{"error":"no exif data"}我如何隐藏此错误消息。 In chrome, the error is 400 (Bad Request) 在Chrome中,错误为400(错误请求)

$http.get(res.getQNUrl(domain, key, "exif"))
    .success(function(data){
        $scope.imageExifMap[key] = data
    }).error(function(data,status,headers,config){})

The error message you mentioned above is browser specific. 您上面提到的错误消息是特定于浏览器的。 It is a browser logging functionality. 它是浏览器的日志记录功能。

Well there is a workaround(not a solution since its not a problem) for it. 好吧,有一种解决方法(因为没有问题,所以没有解决方案)。 I would not recommend it since its a built-in browser functionality you are trying to suppress from doing the task it is meant to do, but if that is what you want then here are couple of ways to achieve it. 我不推荐使用它,因为它内置了浏览器功能,您正试图抑制它打算执行的任务,但是如果您要这样做,可以通过以下几种方法来实现。

  • Using a regular expression filter like so 像这样使用正则表达式过滤器

    ^(?!.* 404 \\(Not Found\\))(?!.*[file name])

  • Using a Log filter like so 像这样使用对数过滤器

在此处输入图片说明

I have not explained it much because there is already an SO question that explains these in detail. 我没有做太多解释,因为已经有一个SO问题可以详细解释这些问题。

Please refer this SO for detailed explanation regarding the above mentioned workarounds. 请参考此SO,以获取有关上述解决方法的详细说明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM