Guest User

Untitled

a guest
Apr 29th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const appRoutes: Routes = [
  2.     {
  3.         path: 'internal-server-error',
  4.         component: InternalServerErrorComponent
  5.     },
  6.     {
  7.         path: 'login',
  8.         component: LoginComponent
  9.     },
  10.     {
  11.         path: 'locked',
  12.         component: LockedComponent
  13.     },
  14.     {
  15.         path: 'weather',
  16.         component: WeatherComponent
  17.     },
  18.     {
  19.         path: '',
  20.         component: AppComponent,
  21.         canActivate: [AuthGuard],
  22.         children:
  23.         [
  24.             {
  25.                 path: 'dashboard',
  26.                 component: DashboardComponent,
  27.                 data: { title: 'Dashboard' }
  28.             },
  29.             {
  30.                 path: 'mail',
  31.                 component: MailComponent,
  32.                 data: { title: 'Mail' }
  33.             },
  34.             {
  35.                 path: 'calendar',
  36.                 component: CalendarComponent,
  37.                 data: { title: 'Calendar' }
  38.             },
  39.             {
  40.                 path: '',
  41.                 redirectTo: '/dashboard',
  42.                 pathMatch: 'full'
  43.             }
  44.         ]
  45.     },
  46.     {
  47.         path: '**',
  48.         component: NotFoundComponent
  49.     },
  50. ];
  51.  
  52. // Error handling
  53. let amountOfErrors:number = 0;
  54. @Injectable()
  55. class MyErrorHandler implements ErrorHandler {
  56.  
  57.     injector: Injector;
  58.  
  59.     constructor(injector:Injector){
  60.         this.injector = injector;
  61.     }
  62.  
  63.     handleError(error) {
  64.         amountOfErrors++;
  65.         console.log("Amount of errors", amountOfErrors);
  66.         console.log("MY ERROR", error);
  67.         // Otherwise, this will cause an infinite loop
  68.         if(amountOfErrors == 1){
  69.             this.injector.get(Router).navigateByUrl("/internal-server-error").then(function(data){
  70.                 console.log("500 THEN:", data);
  71.             });
  72.         }
  73.     }
  74. }
Add Comment
Please, Sign In to add comment