core icon indicating copy to clipboard operation
core copied to clipboard

.use() observable does not send error if http request fails

Open andre-arsenault opened this issue 7 years ago • 5 comments

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

andre-arsenault avatar Jan 10 '18 11:01 andre-arsenault

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.

jaybloke avatar Jan 27 '18 01:01 jaybloke

Same issue here. I want to detect if a json i18n failed to download.

mhosman avatar Feb 24 '18 20:02 mhosman

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)

CodeAndWeb avatar Mar 27 '18 19:03 CodeAndWeb

#474 #630

CodeAndWeb avatar Mar 28 '18 21:03 CodeAndWeb

Related to: #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)

Can you provide an example of such a TranslateLoader? Thanks

SandeepThomas avatar Nov 14 '18 07:11 SandeepThomas

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

rbalet avatar Aug 04 '25 17:08 rbalet