Here is the code snippet that I am working with:
this.http.post(url, payload)
.subscribe(
(req:any)=>{
if(req.status != 200){
console.log('non 200 status');
The this.http
in my code refers to a service that I have injected into the system:
post(url, payload){
return this.http.post(url, payload, { observe: 'response' });
}
In this code, I am observing the entire response.
Although I am able to log the request and receive information about the httpresponseerror object's status, my code seems to be not functioning correctly as expected.
core.js:14597 ERROR
HttpErrorResponse {headers: HttpHeaders, status: 400, statusText: "Bad Request", url: "http://127.0.0.1:8080/api/user/user", ok: false, …}
error: {failcontext: "That email is already in use"}
headers: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ}
message: "Http failure response for http://127.0.0.1:8080/api/user/user: 400 Bad Request"
name: "HttpErrorResponse"
ok: false
status: 400
statusText: "Bad Request"
url: "http://127.0.0.1:8080/api/user/user"
__proto__: HttpResponseBase
I am puzzled why my code is not behaving as intended. Any help would be appreciated!