Handling Expected errors
- To simulate 404 pass id greater than 100
deletePost() {
this.service.deletePost(345)
..subscribe(
data => {},
(error: Response) => {
if(error.status === 404)
alert("post already deleted")
else
alert("An unexpected server occured")
console.log(error);
}
)
}
createPost() {
this.service.createPost(post)
.subscribe(
data => {}
(error: Response) => {
if(error.status == 400) {
alert("error occured");
//this.form.setErrors(error.json());
}
else {
alert("Unexpected error occured");
}
}
)
}