vendredi 6 octobre 2017

Angular 2 handle error although handled in code, zone.js throws error or pollyfills.bundle.js would throw an error

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

Aucun commentaire:

Enregistrer un commentaire