Angular HttpClient Not Executing Code After Request

Discussão em 'Angular' iniciado por webdevoc, Fevereiro 15, 2025.

  1. webdevoc

    webdevoc Guest

    I have a simple Post request being made from angular to my .net api. When I make the post request the debugger shows the execution continue and never hit the block of code from the response.

    I can see the api code process and return a value. However the angular code never runs the code to see the response. I should see either response received or the Error updating profile message but I see neither.

    I have checked the url and the body for correctness and I have verified they are correct since I can see the api being hit in the backend.

    Let me know if I need any other information.

    public updateProfile(data: User): Observable<any> {
    const url = environment.baseUrl + '/Auth/update';
    const body = JSON.stringify(data);

    return this.httpC.post(url, body).pipe(
    map((response: any) => {
    console.log('Response received:', response);
    if (response && response.user && response.token) {
    this.authUser = {
    Username: response.user.username,
    Email: response.user.email,
    Jwt: '',
    Firstname: response.user.firstname,
    Lastname: response.user.lastname,
    Phone: response.user.phone,
    Zipcode: response.user.zipcode,
    };
    this.saveUserToLocalStorage();
    return true;
    }
    return false;
    }),
    catchError((error) => {
    console.error('Error updating profile', error);
    return throwError(error);
    })
    );
    }


    I have tried hardcoding the body to guarantee it's there. I have debugged through the interceptor to guarantee the headers are there.

    Continue reading...

Compartilhe esta Página