I am trying to use http.request in Angular - service::
let _request = new Request({
method: "POST",
body:body,
// change url to "./data/data.junk" to generate an error
url: "http://localhost:5000/user/contact",
headers:new Headers({
'Content-Type': 'application/json',
'Authorization': 'Bearer '+token
})
});
return this._http.request(_request)
.map((res:Response) => res.json())
.catch((error:any) => Observable.throw({status:error.status,message:error.json().error}));
And in component :
this._httpService.getContacts()
.subscribe(
(response) => {
console.log(response)
}
)
If response is OK from server. There is no issue. But if I am sending res.status(401).send({error:err.message}) , I not getting any response in .catch().
Please help
this._httpService.getContacts().subscribe( (response) => {console.log(response);} , (error) => {console.log(error);} )error.statusin.catch()