2

I have the following code to handle a 404 exception.

 fileExists(url){
        this.http.get(url)
                  .map(res => res.json())
                  .subscribe(
                      data => console.log(data),
                      err => console.log(err.status));  //when it fails
  }

When the code fialed it reaches to the line err => console.log(err.status) But it shows the error on the console.

enter image description here

So, how can i handle it, in a way that no error shows in the console?

user5363938
  • 831
  • 3
  • 17
  • 32
  • 1
    Possible duplicate of [Check if file exists but prevent 404 error in console from showing up](http://stackoverflow.com/questions/7035466/check-if-file-exists-but-prevent-404-error-in-console-from-showing-up) – Louis Jan 06 '17 at 15:57

1 Answers1

2

The error line is produced by the browser. There is nothing you can do about it.

As workaround you could create an API on the server that doesn't respond with 404 (or any other error code) when requested file doesn't exist, and then handle the alternative error response in Angular code.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567