I have the following question:
I have a http post request in a service. The request returns a object:
export interface IResponse<T> {
Error:boolean
ErrorMessage:string
Data:T
}
If an error is generated in either php or mysql the boolean is set to true with a message. The request from the service:
searchPersons(personSearchObject:PersonSearchObject){
//generate request here
return this.http.post(Config.ServerUrl, "data="+ request, options)
.map( (responseData) => {
this.personResponse = responseData.json()
if (!this.personResponse.Error){
this.persons.next(this.personResponse.Data)
return;
} else {
console.log(this.personResponse.ErrorMessage)
return Observable.throw(new Error(this.personResponse.ErrorMessage))
}
})
}
The request is called from the controller:
this.personSearchService.searchPersons(personSearchObject).subscribe(
result => {},
error => {
console.log("There was an error");
})
}
Now the problem is that the error=> in the controller is only hit when for example the php backend is down, not when I throw the error from the service.
How can I notify the controller that there was an error in the response from the request?
Other question is can I simply leave out the result in the controller, and only catch the error?
Thanks,