1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

Getting the HTTP response's body on a POST request in Angular

Discussão em 'Angular' iniciado por jamonn, Julho 10, 2025.

  1. jamonn

    jamonn Guest

    I am making a Registration form on Angular 13, but when I receive the response from the API the response I get is always treated as an error and not as the actual response. When everything on the backend is OK, the API sends a 200 HTTP code plus a message in the body's response, and when it doesn't, it sends the code 500 and a error message.

    I have tried a lot of different methods to print the response's body on the console but it always prints it as an error.

    The code is:

    this.http.post\<any\>('http://localhost:8090/register', formData, {observe:'response'})
    .subscribe({
    next :(response) => console.log('Response',response),
    error: (error) => console.log('El error',error.error),
    });
    .


    When looking on the dev tools console after sending a correct form it doesn't show an error with the response and the feedback message can be found on the body, and when I send an incorrect form, the console shows the response as an error (as it is a 500 HTTP code) and the error message is present on the body too.

    This is what I'm getting (I tried submitting the same form 2 times, the first comment is what I am getting, I want to get the red part and the next 2 comments are for the second submit):

    [​IMG]

    This is what the network console shows:

    • console [​IMG]
    • headers console [​IMG]
    • response [​IMG]

    Continue reading...

Compartilhe esta Página