Catch error thrown from http.get() thats piped

Discussão em 'Angular' iniciado por sirzento, Janeiro 28, 2025.

  1. sirzento

    sirzento Guest

    I have the following code inside my auth service:

    return this.http
    .get<any>(`${environment().apiUrl}/auth/refresh`, {
    headers: { Authorization: `Bearer ${this.userValue?.refreshToken}` },
    })
    .pipe(
    map(async (data) => {
    let user = this.parseAndReturnUser(data);
    user.refreshToken = this.userValue?.refreshToken;
    this.userSubject.next(user);
    this.startRefreshTokenTimer();
    return data;
    })
    );


    But now I want to error handle this function in case the get call throws an error. I tryed to just enclose everything with try catch but that didn't work. I am a bit lost here on what to do.

    How can I catch the error that was thrown by this.http.get()?

    Continue reading...

Compartilhe esta Página