When using HttpInterceptor
and having 403
error, I refresh the token and navigate back to the previous state/router. The concept works fine till that point.
The issue is when the (previous) url-state is page/component with a form-fields. How can I keep the form data when an interceptor detect 403 error and goes back to this url-state?
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const router = this.injector.get(Router);
return next.handle(request)
.pipe(
catchError((error: HttpErrorResponse) => {
if ( error instanceof HttpErrorResponse ) {
if ( error.status === 403 ) {
.....
router.navigate([ this.activatedRoute.snapshot['_routerState'].url ]);
}
}
if (error.error instanceof ErrorEvent) {
....
}
return throwError(errMsg);
})
);
}