How do I get the HTTP Response in Angular?

Viewed 34

I've been searching the internet for a while, and I can't seem to get this to work. I need to check if the get request gets redirected to an oauth login page (HTTP code 30X). By implementing a check if that redirect happens, I should be able to differentiate users that are logged in, and not logged in.

Component

 private getUser() {
    this.appComponentService.getUser()
      .pipe(finalize(() => this.loading = false))
      .subscribe(header => {
          this.header = header;
        }
      )
  }

Service

public getUser(
     route: string = '/api/user'
 ): Observable<Header> {
        const httpOptions = this.getDefaultOptions();
        return this.http.get<Header>(route, httpOptions)
        .pipe(
            tap(header => catchError(this.handleError(header)))
        );}
  }

Model

import {User} from "./user.model";

export interface Header {
    user: User;
    votesRemaining: number;
    observe: ArrayBuffer;
}

I tried implementing observe: reponse in the GET request in the service, but that doesn't work. I thought it would work adding the observe in the model, but that doesn't work as well. Hope someone can help!

0 Answers
Related