Maxim Bondarenko
Maxim Bondarenko

Reputation: 11

Angular 5: Generic type 'HttpRequest<T>'

After I writed interceptor I get an error:

error TS2314: Generic type 'HttpRequest<T>' requires 1 type argument(s).

This is my source code :

import { Injectable } from '@angular/core';
import { HttpErrorResponse, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import { UserService } from '@dockers/core/user/user.service';

@Injectable()
export class ErrorInterceptor implements HttpInterceptor {
    constructor(private userService: UserService) {}

    intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
        return next.handle(req).catch((err: any) => {
            console.log('Caught error', err);
            if (err instanceof HttpErrorResponse && err.status === 401) {
                this.userService.logoutUser();
            }
            return Observable.throw(err);
        });
    }
}

Any solutions and help would be great. Thanks!

Upvotes: 1

Views: 1008

Answers (1)

OlegI
OlegI

Reputation: 6010

The answer to your question is <T> in 'HttpRequest<T>' should be a concrete type complex or primitive

Upvotes: 1

Related Questions