Skip to content

Commit

Permalink
fix(TranslateService): always handle observable errors
Browse files Browse the repository at this point in the history
There's a bug in RxJS that breaks hot observables if one subscriber ignores errors (see ReactiveX/rxjs#2145 ), which is causing #308. This patch fixes it by always handling observable errors (handling errors is a good idea anyway).

Fixes #308
  • Loading branch information
imgx64 authored and ocombe committed Nov 20, 2016
1 parent c51499b commit 1284b50
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/translate.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export class TranslateService {
}
pending.subscribe((res: any) => {
this.changeLang(lang);
}, (err: any) => {
});

return pending;
Expand All @@ -176,9 +177,8 @@ export class TranslateService {
this.pending.subscribe((res: Object) => {
this.translations[lang] = res;
this.updateLangs();
this.pending = undefined;
}, (err: any) => {
throw err;
}, () => {
this.pending = undefined;
});

Expand Down Expand Up @@ -304,14 +304,17 @@ export class TranslateService {
observer.next(res);
observer.complete();
};
let onError = (err: any) => {
observer.error(err);
};
this.pending.subscribe((res: any) => {
res = this.getParsedResult(res, key, interpolateParams);
if(typeof res.subscribe === "function") {
res.subscribe(onComplete);
res.subscribe(onComplete, onError);
} else {
onComplete(res);
}
});
}, onError);
});
} else {
let res = this.getParsedResult(this.translations[this.currentLang], key, interpolateParams);
Expand Down

0 comments on commit 1284b50

Please sign in to comment.