Question: In Python, how do I turn this:

```
"(test1)(test2)"

```

into this:

```
["test1","test2"]

```

?

Answer: 
The 401 Unauthorized response is usually emitted as an `error` notification from the Angular `HttpClient`. So you'd need to use RxJS [`catchError`](https://rxjs.dev/api/operators/catchError) operator to catch the error and redirect. You could then emit [`NEVER`](https://rxjs.dev/api/index/const/NEVER) constant so that nothing emits after the redirect and keep the observable alive, or emit [`EMPTY`](https://rxjs.dev/api/index/const/EMPTY) constant to complete the observable.

Try the following

```js
import { throwError, NEVER } from 'rxjs';
import { map, catchError } from 'rxjs/operators';

export class ApiService {
  constructor(private http: HttpClient) { }

  public get<T>(
    path: string, 
    params: HttpParams = new HttpParams(), 
    headers: HttpHeaders = new HttpHeaders()
  ): Observable<T> {
    return this.getBodyOfResponseOrRedirect(
      this.http.get<T>(path, {headers, params, observe: 'response'}));
  }

  private getBodyOfResponseOrRedirect<T>(
    responseObservable: Observable<HttpResponse<T>>
  ): Observable<T> {
    return responseObservable.pipe(
      catchError(error => {
        if (!!error.status && error.status === 401) {
          window.location.href = 'https://custom-url';
          return NEVER;            // <-- never emit after the redirect
        }
        return throwError(error);  // <-- pass on the error if it isn't 401
      }),
      map(response =>  response.body)
    );
  }
}

```
@Michael D solution was super helpfull. Based on his comment I implemented the following http interceptor :

```
@Injectable()
export class HttpResponseInterceptor implements HttpInterceptor {

  intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    return next.handle(request).pipe(catchError(error => {
      if (!!error.status && error.status === 401) {
        window.location.href = 'url';
        return NEVER;
      }
      return throwError(error);
    }));
  }

}

```