Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove error messages from browser console (Angular HttpClient)

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

My current code looks like this:

  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');
        }
      })
    );
  }

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 :)


UPDATE:

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

like image 243
Codehan25 Avatar asked Sep 20 '25 10:09

Codehan25


1 Answers

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.

like image 50
Samarpan Avatar answered Sep 23 '25 04:09

Samarpan