core
core copied to clipboard
.use() observable does not send error if http request fails
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 invoking the use() method to switch languages, if the specified language does not exist the Observable returned by the use() method does not call the error handler given to subscribe(). The error cannot be caught by a try/catch block either. Instead, the error is passed on to the app's global exception handler, which in my case is the Angular ErrorHandler.
This prevents the error from being handled at the site where it occurs.
Expected/desired behavior
For all methods that return an Observable, the Observable should invoke the error handler it given to subscribe() if an error occurs.
Reproduction of the problem Plunker showing the issue. When you use the drop-down to switch to the 'missing' language, the custom error handler is not invoked. You can see that the 'success' and 'complete' handlers are used though.
What is the expected behavior?
If an error handler is passed to subscribe(), it should be invoked when an error occurs.
What is the motivation / use case for changing the behavior? Consistency and matching developer expectations.
Please tell us about your environment:
-
ngx-translate version: 9.0.2
-
Angular version: 5.0.0
-
Browser: all
Also experiencing same issue in an ionic app. The app loads remote translations at start up and is unable to catch a 404 or when there is no internet connectivity.
Same issue here. I want to detect if a json i18n failed to download.
Related to: https://github.com/ngx-translate/core/issues/751 In this case: JSON is invalid.
I suppose the best position to catch the error is creating a TranslateLoader that handles the failed loading (missing file, invalid json)
#474 #630
Related to: #751 In this case: JSON is invalid.
I suppose the best position to catch the error is creating a
TranslateLoaderthat handles the failed loading (missing file, invalid json)
Can you provide an example of such a TranslateLoader? Thanks
I've added a showLog logic that will let your see the http errors.
You will also have an example and will be able to expand his logic if needed.
Here's for the PR -> https://github.com/ngx-translate/core/pull/1570
Cheers