ngx-translate / core

The internationalization (i18n) library for Angular
MIT License
4.51k stars 576 forks source link

uncaught exception for failed request to get dictionary file #390

Closed tristanmkernan closed 6 years ago

tristanmkernan commented 7 years ago

I'm submitting a ... (check one with "x")

[x] bug report => check the FAQ and search github for a similar issue or PR before submitting
[ ] support request => check the FAQ and search github for a similar issue before submitting
[ ] feature request

Current behavior

when a translation is requested in translateService.use('lang'), if the language is not found (i.e. 404), there is an uncaught exception that is not propagated to supplied error handler.

this.translateService
            .use(lang)
            .subscribe(
            success => {
                // handle success
            },
            error => {
                console.log(error);

                // handle error
            }
        );

error is never reached.

Expected/desired behavior

no uncaught exception, error is called.

Reproduction of the problem If the current behavior is a bug or you can illustrate your feature request better with an example, please provide the steps to reproduce and if possible a minimal demo of the problem via https://plnkr.co or similar (you can use this template as a starting point: http://plnkr.co/edit/tpl:btpW3l0jr5beJVjohy1Q).

delete your set translation dictionary and refresh the page.

What is the motivation / use case for changing the behavior?

correct error handling for cases where retrieving the dictionary file fails, whether it's due to network conditions or whatever. i would also like to be able to display a notification on screen when the request fails.

Please tell us about your environment:

ocombe commented 7 years ago

Did you try to use catch on the observable to see if it catches anything?

tristanmkernan commented 7 years ago

i tried the catch operator, but it did not work.

per http://reactivex.io/documentation/operators/catch.html

The Catch operator intercepts an onError notification from the source Observable and, instead of passing it through to any observers, replaces it with some other item or sequence of items, potentially allowing the resulting Observable to terminate normally or not to terminate at all.

in a previous version of your code (2.2.2), i had resolved the issue by changing this code

https://github.com/ngx-translate/core/blob/master/src/translate.service.ts#L190

to include an onError that did nothing. the error was then propagated to my error handler function.

trumbitta commented 7 years ago

@russon77 did you manage to find a workaround for this?

ocombe commented 6 years ago

Hello, I'm closing this issue because it's too old. If you have a similar problem with recent version of the library, please open a new issue.