http-loader icon indicating copy to clipboard operation
http-loader copied to clipboard

Support for error handling from `http.get`

Open ajcrites opened this issue 8 years ago • 3 comments

Currently if there are any errors from http.get (e.g. the file does not exist) the error is propagated to the top level of the app and there's no way to catch it.

I suggest support for adding an error handler function -- something like:

    constructor(private http: HttpClient, public prefix: string = "/assets/i18n/", public suffix: string = ".json", public errorHandler?: () => any) {}

    public getTranslation(lang: string): any {
      const obs = this.http.get(url);
      if (this.errorHandler) {
        obs.catch(this.errorHandler);
      }

      return obs;
    }

ajcrites avatar Sep 20 '17 19:09 ajcrites

I have also encountered the same problem. This is reproducable if you pass an locale to translate.use which has no translations file. This raises an http error but the error part of the Observable of translate.use is not called.

NiklasMerz avatar Oct 23 '17 08:10 NiklasMerz

I also would love to have support for catching errors. We have a global error handler that sends all global errors to us.

We would like to be able to catch errors originating from this and display an appropriate error message.

chris13524 avatar Apr 12 '19 15:04 chris13524

we need this

orcunozbay1 avatar Jun 17 '20 13:06 orcunozbay1