从浏览器控制台中删除错误消息(Angular HttpClient) [英] Remove error messages from browser console (Angular HttpClient)

查看:285
本文介绍了从浏览器控制台中删除错误消息(Angular HttpClient)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HttpClient是否可以从浏览器控制台中删除错误消息?

Is there a way with the HttpClient to remove error messages from the browser console?

我当前的代码如下:

  getStuff(stuffId: string): Observable<Stuff[]> {
    return this.httpClient.get<Stuff[]>(this.stuff() + stuffId + '/stuff/').pipe(
      catchError((err) => {
        console.log(err.status);
        if (err.status === 404) {
          console.log('Not found');
        }
      })
    );
  }

执行if语句中的console.log('Not found') ,但仍会向控制台抛出标准错误。

My console.log('Not found') within the if statement is executed, but it still throws the standard error to the console.

我的目标:控制台中没有红色:)

My goal: nothing red in the console :)

更新:

错误不是在Firefox中引发,而是在Google Chrome中引发。为什么..?

The errors are not thrown in Firefox, but in Google Chrome. Why..?

推荐答案

您在控制台中看到的标准错误实际上并非来自代码。由于API错误,它来自网络。浏览器考虑并理解标准的http响应代码。因此,无论何时任何http请求返回2xx以外的任何响应代码,他们都将其视为错误并在控制台中以红色显示。
很遗憾,您无法将其删除。这是由浏览器完成的。

The standard error you are seeing in console is actually not from code. Its from network, due to API error. The browsers consider and understand standard http response codes. So, whenever any response code other than 2xx is returned by any http request, they consider it an error and show it in red in console. Unfortunately you cannot remove it. That's done by browser.

这篇关于从浏览器控制台中删除错误消息(Angular HttpClient)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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