I am trying to pass errors from my API to the Angular 4 application. The problem is that on the angular side I do not see proper error message:
Web Api error is generated like this:
throw new HttpResponseException(
new HttpResponseMessage(HttpStatusCode.BadRequest)
{
Headers = {{"errorMessage", "Message in header"}},
Content = new StringContent("Message in body")
}
);
My angular code is something like:
return this._http.get<IMyObj[]>(this._serviceUrl)
.do(this.handleSuccessResponse)
.catch(this.handleErrorResponse);
protected handleErrorResponse(err: HttpErrorResponse) {
console.info(err);
// some logic based on code
}
The problem is that if I check err it's "error" property is null, message is "Response failed for url" and no custom header, however on the network tab in the browser I can see my custom header with error as well as error in body. How do I access any of this messages from my angular app?