Read the response header when the status is 302 in Angular

718 Views Asked by At

How can I read the response header of XHR call by $http in Angular (v8+) as its status is 302 and it is redirected by browser? In my case as the redirect url has a different origin, I only get an Unknown error from the code below:

return this.http.get('/oauth2/authorization/keycloak').pipe(
        map(res => {
          // never called
          console.log(res);
          return res;
        }),
        tap( res => {
          // never called
          console.log(res);
        }),
        catchError(err => {
          // prints "Unknown Error"
          console.log(err);
          return err;
        })
      );
1

There are 1 best solutions below

2
On