0

I am trying to handle error while a service call is made from my application. While calling the service as following, I am able to handle the error during service call.

searchRequests(Model):Observable<any>{
    this.headers1.set('content-type', 'application/json');
    let options = new RequestOptions({ headers: this.headers1});
    return this.http.post(this.Url,Model,options).map((res:Response) => res.json())
      .catch((err:any, caught:Observable<any>) => {return Observable.throw(new Error(err))})
  }

In my component I am handling the error like this and just printing over console, which works absolutely fine while printing

this.service.searchRequests(StringArray).toPromise().then((searchResponse => {
        this.selectedData = searchResponse;
    }))
.catch(err => console.log('Error while search service call ' +err));

As per my understanding, this should work okay. but when I receive an error while service call, there is an error received from Polyfills.bundle.js over console. This is something I am not able to handle. Is there a way this error can be handled and there is no error over console. not sure how can I handle error in libraries. Any help would be hugely appreciated

Error at console is POST https:localhost:8080/searchRequests500 (Internal Server Error) zone:js:2933

DP3
  • 108
  • 6
  • 19

1 Answers1

0

As per my understanding of the REST concepts this is the expected behavior of all REST APIs.

But if still want to remove the errors in the console, then I am afraid then that you can't really do anything, this is the behavior of Chrome browser.

Here is the link below for more info.

Can I prevent the Chrome Developer Tools console from logging image 404 errors?

Srinivas Valekar
  • 1,083
  • 10
  • 19