Recently, I spent hours following a tutorial on jwt refresh tokens, only to discover that the code was outdated and some changes were required. As a result, I created an interceptor which encountered an issue with the Observable component, leaving me unsure of how to resolve it.
The Error Message Reads:
"Function lacks ending return statement and return type does not include 'undefined'"
I am aware that this error is due to my Observable not having a specific return.
This is the code snippet causing trouble:
intercept(request : HttpRequest<any>, next : HttpHandler): Observable<HttpEvent<any>>
{
// Check if the user is logging in for the first time
return next.handle(this.attachTokenToRequest(request)).pipe(
tap((event : HttpEvent<any>) => {
if(event instanceof HttpResponse)
{
console.log("Success");
}
}),
catchError((err) : Observable<any> => { //Here comes the error message
if(err instanceof HttpErrorResponse) {
switch((<HttpErrorResponse>err).status)
{
case 401:
console.log("Token expired. Attempting refresh ...");
return this.handleHttpResponseError(request, next);
case 400:
return <any>this.acct.logout();
}
} else
{
return throwError(this.handleError);
}
//I think here should be a return but I don't know which kind, tried already a few ones
})
);
}
If you'd like to reference the original tutorial code, you can find it at the following link: