I have a POST call to rest api from my angular service, and I want to return either the error status or the error message to do some logic on it, but am always getting [Object] as response (or undefined, depends on what I return from my error handling method) and I'm not managing to parse it!
From my service:
addDbResource(resource) {
//console.log(JSON.stringify(resource));
this.http.post(this.url + "resource", JSON.stringify(resource), this.options)
//.map(this.extractData)
.map(res => this.errorStatus = res)
.catch(this.handleObservableError)
.subscribe();
return this.errorStatus;
}
private handleObservableError (error: Response | any) {
//console.error("Error1: " + error.message || error);
let errMsg = (error.message) ? error.message :
error.status ? error.status + " - " + error.statusText : 'Server error';
document.getElementById("alert").innerHTML = error.json().message;
return Observable.throw(error.status);
//return Observable.throw(error.message || error);
//return error.status;
}
PSB a screenshot