In my Angular project, I've integrated the following code within a class that extends Angular's HttpInterceptor:
handleError(error: unknown): Promise<boolean> {
if (error instanceof HttpErrorResponse) {
return this.router.navigate([NOT_FOUND_URL, this.errorDescriptionProvider.getHttpErrorDescription(error)]);
}
else
return this.router.navigate([NOT_FOUND_URL, this.errorDescriptionProvider.getUnspecifiedNetworkErrorDescription()])
}
and also this:
intercept(req: HttpRequest<T>, next: HttpHandler): Observable<HttpEvent<unknown>> {
const stream = next
.handle(req)
.pipe
(
catchError(x => from(this.handleError(x)))
);
//Encountering an error stating that it is not assignable to Observable<HttpEvent<unknow>> due to its type being Observable<boolean |....>
return stream;
}
What's the best way to achieve automatic redirection on HTTP errors?