1

I am making an http request with Angular HttpClient.

http.get(`${hostUrl}/myproject/infrastructure-status`)
.subscribe(
(resp) => {
  // handle response
},
(error) => {
 console.log(error)
});

In my console, an error of type HttpErrorResponse is logged: Error logged on console

However, the backend response on my network tab is not the same:

Headers error network tab

enter image description here

Can I get the full error response in Angular? If so, how?

1 Answer 1

1

The error you get is also a response object so if you cast it to response you can read the body. For me this works:

http.get(`${hostUrl}/myproject/infrastructure-status`)
           .subscribe(
           (resp) => {
              // handle response
           },
           (error) => {
              if (error instanceof Response) {
                 console.log(error.text());
              }
           });

What seems strange to me is that you get a ProgressEventObject. I always get a Response object that includes the body also. Maybe the difference is that the response in your case is HTML I was testing with calling a WebApi that returns JSON.

Sign up to request clarification or add additional context in comments.

1 Comment

ProgressEvent is obtainable by flag.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.