title: Nestjs Interceptor how to catch http 401 error and resubmit original request
body: <p>I need to write an http header interceptor to add Authorization header, if there is a 401 error, submit another request for a new token, then resubmit the original request with the new token.</p>
  <pre><code>intercept(context: ExecutionContext, next: CallHandler): Observable&lt;any&gt; {
  
      const request = context.switchToHttp().getRequest();
      const response = context.switchToHttp().getResponse();
  
      return next.handle().pipe(
  
        catchError(async error =&gt; {
  
          if (error.response.status === 401) {
  
            const originalRequest = error.config;
  
            var authRes = await this.authenticationService.getAccessToken();
            
            this.authenticationService.accessTokenSubject.next(authRes.access_token);
  
            // I need to resubmit the original request with the new token from here
            // but return next.handle(originalRequest) doesn't work
  
          }
          return throwError(error);
  
        }),
                  
      );
    }
  </code></pre>
  <p>But next.handle(originalRequest) doesn't work. How to resubmit the original request in the interceptor? Thank you very much in advance for your help.</p>