I have api which returns 400 or 404 errors if failed.
When I run the http.get method, it does not catch the error on subscribe and throws error.
Http.get(`api/path/here`).map(res => res.json()).subscribe(
data => console.log(data),
error => console.log(error)
);
Following is the error I get
You could also use the catch
operator
http.get(`api/path/here`)
.map(res => res.json())
.catch(
err => {
// handle errors
})
.subscribe(
data => console.log(data)
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With