Answer the question
In order to leave comments, you need to log in
Angular2 500 error page?
How to make a redirect to a page with a 500 error due to network failures or other problems? Here is my routing for now
import { Routes, RouterModule } from '@angular/router';
import { ModuleWithProviders } from '@angular/core';
import { DasboardComponent} from '../layout/dasboard.component';
import { SignInComponent } from '../layout/sign-in/sign-in.component';
import { NotFoundComponent } from '../layout/not-found/not-found.component';
import {AuthGuard} from '../shared/guards/auth.guard';
export const routes: Routes = [
{ path: '', redirectTo: 'dasboard', pathMatch: 'full' },
{ path: 'sign_in', component: SignInComponent },
{ path: 'dasboard', component: DasboardComponent, canActivate: [AuthGuard] },
{ path: 'not_found', component: NotFoundComponent },
{ path: '**', component: NotFoundComponent }
];
export const routing: ModuleWithProviders = RouterModule.forRoot(routes, { useHash: true });
Answer the question
In order to leave comments, you need to log in
import { Injectable, Injector } from '@angular/core'
import {
HttpEvent,
HttpInterceptor,
HttpHandler,
HttpRequest
} from '@angular/common/http'
import { Observable } from 'rxjs/Observable'
import 'rxjs/add/observable/throw'
import 'rxjs/add/operator/catch'
@Injectable()
export class MyHttpInterceptor implements HttpInterceptor {
intercept(
req: HttpRequest<any>,
next: HttpHandler
): Observable<HttpEvent<any>> {
console.log('intercepted request ... ')
return next.handle(req).catch((error, caught) => {
// Проверяем код ошибки. Берём роутер и перенаправляем куда вам угодно.
return Observable.throw(error)
}) as any
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question