angular-seed-advanced
angular-seed-advanced copied to clipboard
LogService used inside catch operator for http requests blocks the chain
I'm submitting a ... (check one with "x")
[x ] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see use [gitter](https://gitter.im/mgechev/angular2-seed) or [stackoverflow](https://stackoverflow.com/questions/tagged/angular2)
Current behavior
In my ApiService if I use the LogService inside of the catch operator the Observable is blocked and the catch operator of my original function in the component returns the following error
{"line":62,"column"
:17,"sourceURL":"file:///app/app/modules/core/services/api.service.js"}
At line 62 starts my handleError function
It works when I use a simple console.log
It happens on ios simulator with Nativescript. I have not tried on web/desktop versions
Expected behavior
Avoid blocking the chain and return the original http error
Minimal reproduction of the problem with instructions
import { Injectable } from "@angular/core";
import { Headers, Http, RequestOptions, URLSearchParams, Response } from "@angular/http";
import { Config } from "../utils/config";
import { LogService } from "./logging/log.service";
import "rxjs/add/operator/map";
import "rxjs/add/operator/do";
import "rxjs/add/operator/catch";
import "rxjs/add/operator/mergeMap";
import { Observable } from "rxjs/Observable";
@Injectable()
export class ApiService {
url: string = Config.ENVIRONMENT().API;
constructor(public http: Http,
private log: LogService) { }
private extractData(res: Response) {
let body = res.json();
return body.data ? body.data : body || {};
}
private handleError(err) {
// THIS BLOCKS THE OBSERVABLE, console.log works
this.log.debug("Error: " + err);
return Observable.throw(err);
}
public post(endpoint: string, body: any, options?: RequestOptions) {
if (!options) {
options = new RequestOptions({
headers: new Headers({
"Content-Type": "application/json",
"Accept": "application/json"
})
});
}
return this.http.post(this.url + endpoint, body, options)
.map(this.extractData)
.catch(this.handleError);
}
}
What is the motivation / use case for changing the behavior?
Same as expected behavior
Please tell us about your environment:
macOS 10.10.5 / Visual Studio Code
-
Angular Seed Version:
88ca3445175c29ae1c182cb2e9e64ae0a7f99edb
-
Node:
node --version= 7.10