I'm working on an Angular 2 service returning data from a restful WebApi backend.
I'm trying to make it gracefully handle the service not being available however I'm getting unexpected information in the error responses.
Here's the code
update(fund, transactionId:string, showToastOnError: boolean, useCorrectUrl: boolean) {
let options = this.getStartCall();
options.headers.append("transaction-id", transactionId)
let url = fundsUrl + (useCorrectUrl ? "" : "breakTheUrl");
return this._http.put(url, JSON.stringify(fund), options)
.map(res => res.json())
//.retry(5)
.catch(errorResponse => {
let res = <Response>errorResponse;
let err = res.json();
let emsg = err ?
(err.error ? err.error : JSON.stringify(err)) :
(res.statusText || 'unknown error');
this._logger.log(emsg, "The fund was not updated", LogLevel.Error, showToastOnError);
return Observable.throw(emsg);
})
.finally(() => this._spinnerService.hide());
}
When I look at the network traffic I see the 404 error as expected.
My problem is in my catch function.
Here's the value's I'm seeing:
JSON.stringify(errorResponse)
{"_body":{"isTrusted":true},"status":200,"statusText":"Ok","headers":{},"type":3,"url":null}"
errorResponse.json()
bubbles: false
cancelBubble: false
cancelable: false
currentTarget: XMLHttpRequest
defaultPrevented: false
eventPhase: 2
isTrusted: true
isTrusted: true
lengthComputable: false
loaded: 0
path: Array[0]
position: 0
returnValue: true
srcElement: XMLHttpRequest
target: XMLHttpRequest
timeStamp: 1460990458693
total: 0
totalSize: 0
type: "error"
__proto__: XMLHttpRequestProgressEvent
Am I doing something wrong here or is this a bug in Angular2 beta 15?