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?

1

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.