I have a simple angular2 http get call like below
import { Http, Response } from '@angular/http';
@Injectable()
export class ServiceBase {
protected resource: string;
constructor(private _http: Http) { }
getTnCByCountryCodeNdType(countryCode: string, tncType: string) {
let url = `${CONFIG.URL}/tnc?countryCode=${country}&tnc=${tnc}`;
return this._http.get(url, this.getHeader())
.map((res: Response) => {
return res.json();
});
}
}
The Error response from the above when received,
I tried
this.service
.getTnCByCountryCodeNdType('MY', this.tnc.toLowerCase())
.subscribe(x => {
//
},
(err: Response) => {
error = JSON.parse(err);
});
where: err is the response error;
and it threw the usual json error .
EXCEPTION: Unexpected token R in JSON at position 0
To my surprise
error = err.json();
Works fine. What is the difference between the two and why does the first one failed? Any help is appreciated
erris not defined or even declared in the code you've provided