[DSC-287] Created new page error 500, added guard to check for initial api request, redirect to page 500

This commit is contained in:
Rezart Vata
2021-11-04 14:21:12 +01:00
parent 2fe9fbd584
commit fc6678515a
10 changed files with 164 additions and 26 deletions

View File

@@ -89,6 +89,12 @@ export function getPageNotFoundRoute() {
return `/${PAGE_NOT_FOUND_PATH}`; return `/${PAGE_NOT_FOUND_PATH}`;
} }
export const INTERNAL_SERVER_ERROR = '500';
export function getPageInternalServerErrorRoute() {
return `/${INTERNAL_SERVER_ERROR}`;
}
export const INFO_MODULE_PATH = 'info'; export const INFO_MODULE_PATH = 'info';
export function getInfoModulePath() { export function getInfoModulePath() {
return `/${INFO_MODULE_PATH}`; return `/${INFO_MODULE_PATH}`;

View File

@@ -26,6 +26,9 @@ import { SiteRegisterGuard } from './core/data/feature-authorization/feature-aut
import { ThemedPageNotFoundComponent } from './pagenotfound/themed-pagenotfound.component'; import { ThemedPageNotFoundComponent } from './pagenotfound/themed-pagenotfound.component';
import { ThemedForbiddenComponent } from './forbidden/themed-forbidden.component'; import { ThemedForbiddenComponent } from './forbidden/themed-forbidden.component';
import { GroupAdministratorGuard } from './core/data/feature-authorization/feature-authorization-guard/group-administrator.guard'; import { GroupAdministratorGuard } from './core/data/feature-authorization/feature-authorization-guard/group-administrator.guard';
import { ThemedPageInternalServerErrorComponent } from './page-internal-server-error/themed-page-internal-server-error.component';
import { ServerCheckGuard } from './core/server-check/server-check.guard';
@NgModule({ @NgModule({
imports: [ imports: [
@@ -33,157 +36,160 @@ import { GroupAdministratorGuard } from './core/data/feature-authorization/featu
path: '', canActivate: [AuthBlockingGuard], path: '', canActivate: [AuthBlockingGuard],
children: [ children: [
{ path: '', redirectTo: '/home', pathMatch: 'full' }, { path: '', redirectTo: '/home', pathMatch: 'full' },
{ path: 'reload/:rnd', component: ThemedPageNotFoundComponent, pathMatch: 'full', canActivate: [ReloadGuard] }, { path: 'reload/:rnd', component: ThemedPageNotFoundComponent, pathMatch: 'full', canActivate: [ServerCheckGuard, ReloadGuard] },
{ {
path: 'home', path: 'home',
loadChildren: () => import('./home-page/home-page.module') loadChildren: () => import('./home-page/home-page.module')
.then((m) => m.HomePageModule), .then((m) => m.HomePageModule),
data: { showBreadcrumbs: false }, data: { showBreadcrumbs: false },
canActivate: [EndUserAgreementCurrentUserGuard] canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard]
}, },
{ {
path: 'community-list', path: 'community-list',
loadChildren: () => import('./community-list-page/community-list-page.module') loadChildren: () => import('./community-list-page/community-list-page.module')
.then((m) => m.CommunityListPageModule), .then((m) => m.CommunityListPageModule),
canActivate: [EndUserAgreementCurrentUserGuard] canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard]
}, },
{ {
path: 'id', path: 'id',
loadChildren: () => import('./lookup-by-id/lookup-by-id.module') loadChildren: () => import('./lookup-by-id/lookup-by-id.module')
.then((m) => m.LookupIdModule), .then((m) => m.LookupIdModule),
canActivate: [EndUserAgreementCurrentUserGuard] canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard]
}, },
{ {
path: 'handle', path: 'handle',
loadChildren: () => import('./lookup-by-id/lookup-by-id.module') loadChildren: () => import('./lookup-by-id/lookup-by-id.module')
.then((m) => m.LookupIdModule), .then((m) => m.LookupIdModule),
canActivate: [EndUserAgreementCurrentUserGuard] canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard]
}, },
{ {
path: REGISTER_PATH, path: REGISTER_PATH,
loadChildren: () => import('./register-page/register-page.module') loadChildren: () => import('./register-page/register-page.module')
.then((m) => m.RegisterPageModule), .then((m) => m.RegisterPageModule),
canActivate: [SiteRegisterGuard] canActivate: [ServerCheckGuard, SiteRegisterGuard]
}, },
{ {
path: FORGOT_PASSWORD_PATH, path: FORGOT_PASSWORD_PATH,
loadChildren: () => import('./forgot-password/forgot-password.module') loadChildren: () => import('./forgot-password/forgot-password.module')
.then((m) => m.ForgotPasswordModule), .then((m) => m.ForgotPasswordModule),
canActivate: [EndUserAgreementCurrentUserGuard] canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard]
}, },
{ {
path: COMMUNITY_MODULE_PATH, path: COMMUNITY_MODULE_PATH,
loadChildren: () => import('./community-page/community-page.module') loadChildren: () => import('./community-page/community-page.module')
.then((m) => m.CommunityPageModule), .then((m) => m.CommunityPageModule),
canActivate: [EndUserAgreementCurrentUserGuard] canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard]
}, },
{ {
path: COLLECTION_MODULE_PATH, path: COLLECTION_MODULE_PATH,
loadChildren: () => import('./collection-page/collection-page.module') loadChildren: () => import('./collection-page/collection-page.module')
.then((m) => m.CollectionPageModule), .then((m) => m.CollectionPageModule),
canActivate: [EndUserAgreementCurrentUserGuard] canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard]
}, },
{ {
path: ITEM_MODULE_PATH, path: ITEM_MODULE_PATH,
loadChildren: () => import('./item-page/item-page.module') loadChildren: () => import('./item-page/item-page.module')
.then((m) => m.ItemPageModule), .then((m) => m.ItemPageModule),
canActivate: [EndUserAgreementCurrentUserGuard] canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard]
}, },
{ path: 'entities/:entity-type', { path: 'entities/:entity-type',
loadChildren: () => import('./item-page/item-page.module') loadChildren: () => import('./item-page/item-page.module')
.then((m) => m.ItemPageModule), .then((m) => m.ItemPageModule),
canActivate: [EndUserAgreementCurrentUserGuard] canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard]
}, },
{ {
path: LEGACY_BITSTREAM_MODULE_PATH, path: LEGACY_BITSTREAM_MODULE_PATH,
loadChildren: () => import('./bitstream-page/bitstream-page.module') loadChildren: () => import('./bitstream-page/bitstream-page.module')
.then((m) => m.BitstreamPageModule), .then((m) => m.BitstreamPageModule),
canActivate: [EndUserAgreementCurrentUserGuard] canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard]
}, },
{ {
path: BITSTREAM_MODULE_PATH, path: BITSTREAM_MODULE_PATH,
loadChildren: () => import('./bitstream-page/bitstream-page.module') loadChildren: () => import('./bitstream-page/bitstream-page.module')
.then((m) => m.BitstreamPageModule), .then((m) => m.BitstreamPageModule),
canActivate: [EndUserAgreementCurrentUserGuard] canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard]
}, },
{ {
path: 'mydspace', path: 'mydspace',
loadChildren: () => import('./my-dspace-page/my-dspace-page.module') loadChildren: () => import('./my-dspace-page/my-dspace-page.module')
.then((m) => m.MyDSpacePageModule), .then((m) => m.MyDSpacePageModule),
canActivate: [AuthenticatedGuard, EndUserAgreementCurrentUserGuard] canActivate: [ServerCheckGuard, AuthenticatedGuard, EndUserAgreementCurrentUserGuard]
}, },
{ {
path: 'search', path: 'search',
loadChildren: () => import('./search-page/search-page-routing.module') loadChildren: () => import('./search-page/search-page-routing.module')
.then((m) => m.SearchPageRoutingModule), .then((m) => m.SearchPageRoutingModule),
canActivate: [EndUserAgreementCurrentUserGuard] canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard]
}, },
{ {
path: 'browse', path: 'browse',
loadChildren: () => import('./browse-by/browse-by-page.module') loadChildren: () => import('./browse-by/browse-by-page.module')
.then((m) => m.BrowseByPageModule), .then((m) => m.BrowseByPageModule),
canActivate: [EndUserAgreementCurrentUserGuard] canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard]
}, },
{ {
path: ADMIN_MODULE_PATH, path: ADMIN_MODULE_PATH,
loadChildren: () => import('./admin/admin.module') loadChildren: () => import('./admin/admin.module')
.then((m) => m.AdminModule), .then((m) => m.AdminModule),
canActivate: [SiteAdministratorGuard, EndUserAgreementCurrentUserGuard] canActivate: [ServerCheckGuard, SiteAdministratorGuard, EndUserAgreementCurrentUserGuard]
}, },
{ {
path: 'login', path: 'login',
loadChildren: () => import('./login-page/login-page.module') loadChildren: () => import('./login-page/login-page.module')
.then((m) => m.LoginPageModule), .then((m) => m.LoginPageModule),
canActivate: [ServerCheckGuard]
}, },
{ {
path: 'logout', path: 'logout',
loadChildren: () => import('./logout-page/logout-page.module') loadChildren: () => import('./logout-page/logout-page.module')
.then((m) => m.LogoutPageModule), .then((m) => m.LogoutPageModule),
canActivate: [ServerCheckGuard]
}, },
{ {
path: 'submit', path: 'submit',
loadChildren: () => import('./submit-page/submit-page.module') loadChildren: () => import('./submit-page/submit-page.module')
.then((m) => m.SubmitPageModule), .then((m) => m.SubmitPageModule),
canActivate: [EndUserAgreementCurrentUserGuard] canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard]
}, },
{ {
path: 'import-external', path: 'import-external',
loadChildren: () => import('./import-external-page/import-external-page.module') loadChildren: () => import('./import-external-page/import-external-page.module')
.then((m) => m.ImportExternalPageModule), .then((m) => m.ImportExternalPageModule),
canActivate: [EndUserAgreementCurrentUserGuard] canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard]
}, },
{ {
path: 'workspaceitems', path: 'workspaceitems',
loadChildren: () => import('./workspaceitems-edit-page/workspaceitems-edit-page.module') loadChildren: () => import('./workspaceitems-edit-page/workspaceitems-edit-page.module')
.then((m) => m.WorkspaceitemsEditPageModule), .then((m) => m.WorkspaceitemsEditPageModule),
canActivate: [EndUserAgreementCurrentUserGuard] canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard]
}, },
{ {
path: WORKFLOW_ITEM_MODULE_PATH, path: WORKFLOW_ITEM_MODULE_PATH,
loadChildren: () => import('./workflowitems-edit-page/workflowitems-edit-page.module') loadChildren: () => import('./workflowitems-edit-page/workflowitems-edit-page.module')
.then((m) => m.WorkflowItemsEditPageModule), .then((m) => m.WorkflowItemsEditPageModule),
canActivate: [EndUserAgreementCurrentUserGuard] canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard]
}, },
{ {
path: PROFILE_MODULE_PATH, path: PROFILE_MODULE_PATH,
loadChildren: () => import('./profile-page/profile-page.module') loadChildren: () => import('./profile-page/profile-page.module')
.then((m) => m.ProfilePageModule), .then((m) => m.ProfilePageModule),
canActivate: [AuthenticatedGuard, EndUserAgreementCurrentUserGuard] canActivate: [ServerCheckGuard, AuthenticatedGuard, EndUserAgreementCurrentUserGuard]
}, },
{ {
path: PROCESS_MODULE_PATH, path: PROCESS_MODULE_PATH,
loadChildren: () => import('./process-page/process-page.module') loadChildren: () => import('./process-page/process-page.module')
.then((m) => m.ProcessPageModule), .then((m) => m.ProcessPageModule),
canActivate: [AuthenticatedGuard, EndUserAgreementCurrentUserGuard] canActivate: [ServerCheckGuard, AuthenticatedGuard, EndUserAgreementCurrentUserGuard]
}, },
{ {
path: INFO_MODULE_PATH, path: INFO_MODULE_PATH,
loadChildren: () => import('./info/info.module').then((m) => m.InfoModule), loadChildren: () => import('./info/info.module').then((m) => m.InfoModule),
canActivate: [ServerCheckGuard]
}, },
{ {
path: REQUEST_COPY_MODULE_PATH, path: REQUEST_COPY_MODULE_PATH,
loadChildren: () => import('./request-copy/request-copy.module').then((m) => m.RequestCopyModule), loadChildren: () => import('./request-copy/request-copy.module').then((m) => m.RequestCopyModule),
canActivate: [AuthenticatedGuard, EndUserAgreementCurrentUserGuard] canActivate: [ServerCheckGuard, AuthenticatedGuard, EndUserAgreementCurrentUserGuard]
}, },
{ {
path: FORBIDDEN_PATH, path: FORBIDDEN_PATH,
@@ -193,12 +199,14 @@ import { GroupAdministratorGuard } from './core/data/feature-authorization/featu
path: 'statistics', path: 'statistics',
loadChildren: () => import('./statistics-page/statistics-page-routing.module') loadChildren: () => import('./statistics-page/statistics-page-routing.module')
.then((m) => m.StatisticsPageRoutingModule), .then((m) => m.StatisticsPageRoutingModule),
canActivate: [ServerCheckGuard]
}, },
{ {
path: ACCESS_CONTROL_MODULE_PATH, path: ACCESS_CONTROL_MODULE_PATH,
loadChildren: () => import('./access-control/access-control.module').then((m) => m.AccessControlModule), loadChildren: () => import('./access-control/access-control.module').then((m) => m.AccessControlModule),
canActivate: [GroupAdministratorGuard], canActivate: [ServerCheckGuard, GroupAdministratorGuard],
}, },
{ path: '500', component: ThemedPageInternalServerErrorComponent },
{ path: '**', pathMatch: 'full', component: ThemedPageNotFoundComponent }, { path: '**', pathMatch: 'full', component: ThemedPageNotFoundComponent },
]} ]}
],{ ],{

View File

@@ -53,6 +53,8 @@ import { ThemedFooterComponent } from './footer/themed-footer.component';
import { ThemedBreadcrumbsComponent } from './breadcrumbs/themed-breadcrumbs.component'; import { ThemedBreadcrumbsComponent } from './breadcrumbs/themed-breadcrumbs.component';
import { ThemedHeaderNavbarWrapperComponent } from './header-nav-wrapper/themed-header-navbar-wrapper.component'; import { ThemedHeaderNavbarWrapperComponent } from './header-nav-wrapper/themed-header-navbar-wrapper.component';
import { IdleModalComponent } from './shared/idle-modal/idle-modal.component'; import { IdleModalComponent } from './shared/idle-modal/idle-modal.component';
import { ThemedPageInternalServerErrorComponent } from './page-internal-server-error/themed-page-internal-server-error.component';
import { PageInternalServerErrorComponent } from './page-internal-server-error/page-internal-server-error.component';
import { UUIDService } from './core/shared/uuid.service'; import { UUIDService } from './core/shared/uuid.service';
import { CookieService } from './core/services/cookie.service'; import { CookieService } from './core/services/cookie.service';
@@ -187,7 +189,9 @@ const DECLARATIONS = [
ThemedBreadcrumbsComponent, ThemedBreadcrumbsComponent,
ForbiddenComponent, ForbiddenComponent,
ThemedForbiddenComponent, ThemedForbiddenComponent,
IdleModalComponent IdleModalComponent,
ThemedPageInternalServerErrorComponent,
PageInternalServerErrorComponent
]; ];
const EXPORTS = [ const EXPORTS = [

View File

@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { ServerCheckGuard } from './server-check.guard';
describe('ServerCheckGuard', () => {
let guard: ServerCheckGuard;
beforeEach(() => {
TestBed.configureTestingModule({});
guard = TestBed.inject(ServerCheckGuard);
});
it('should be created', () => {
expect(guard).toBeTruthy();
});
});

View File

@@ -0,0 +1,30 @@
import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree } from '@angular/router';
import { Observable } from 'rxjs';
import { RootDataService } from '../data/root-data.service';
import { map, tap } from 'rxjs/operators';
import { RemoteData } from '../data/remote-data';
import { getPageInternalServerErrorRoute } from '../../app-routing-paths';
import { Router } from '@angular/router';
@Injectable({
providedIn: 'root'
})
export class ServerCheckGuard implements CanActivate {
constructor(private router: Router,private rootDataService: RootDataService) {}
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
return this.rootDataService.findRoot().pipe(
map( (res: RemoteData<any>) => res.hasSucceeded ),
tap( (responsehasSucceeded: boolean) => {
if (!responsehasSucceeded) {
this.router.navigateByUrl(getPageInternalServerErrorRoute());
}
}),
);
}
}

View File

@@ -0,0 +1,10 @@
<div class="page-internal-server-error container">
<h1>500</h1>
<h2><small>{{"500.page-internal-server-error" | translate}}</small></h2>
<br/>
<p>{{"500.help" | translate}}</p>
<br/>
<!-- <p class="text-center">
<a routerLink="/home" class="btn btn-primary">{{"500.link.home-page" | translate}}</a>
</p> -->
</div>

View File

@@ -0,0 +1,33 @@
import { ServerResponseService } from '../core/services/server-response.service';
import { Component, ChangeDetectionStrategy, OnInit } from '@angular/core';
import { AuthService } from '../core/auth/auth.service';
/**
* This component representing the `PageNotFound` DSpace page.
*/
@Component({
selector: 'ds-page-internal-server-error',
styleUrls: ['./page-internal-server-error.component.scss'],
templateUrl: './page-internal-server-error.component.html',
changeDetection: ChangeDetectionStrategy.Default
})
export class PageInternalServerErrorComponent implements OnInit {
/**
* Initialize instance variables
*
* @param {AuthService} authservice
* @param {ServerResponseService} responseService
*/
constructor(private authservice: AuthService, private responseService: ServerResponseService) {
this.responseService.setNotFound();
}
/**
* Remove redirect url from the state
*/
ngOnInit(): void {
this.authservice.clearRedirectUrl();
}
}

View File

@@ -0,0 +1,26 @@
import { Component } from '@angular/core';
import { ThemedComponent } from '../shared/theme-support/themed.component';
import { PageInternalServerErrorComponent } from './page-internal-server-error.component';
/**
* Themed wrapper for PageInternalServerErrorComponent
*/
@Component({
selector: 'ds-themed-search-page',
styleUrls: [],
templateUrl: '../shared/theme-support/themed.component.html',
})
export class ThemedPageInternalServerErrorComponent extends ThemedComponent<PageInternalServerErrorComponent> {
protected getComponentName(): string {
return 'PageInternalServerErrorComponent';
}
protected importThemedComponent(themeName: string): Promise<any> {
return import(`../../themes/${themeName}/app/page-internal-server-error/page-internal-server-error.component`);
}
protected importUnthemedComponent(): Promise<any> {
return import(`./page-internal-server-error.component`);
}
}

View File

@@ -14,6 +14,11 @@
"403.forbidden": "forbidden", "403.forbidden": "forbidden",
"500.page-internal-server-error": "Internal Server Error",
"500.help": "There was an error with the server.",
"500.link.home-page": "Take me to the home page",
"404.help": "We can't find the page you're looking for. The page may have been moved or deleted. You can use the button below to get back to the home page. ", "404.help": "We can't find the page you're looking for. The page may have been moved or deleted. You can use the button below to get back to the home page. ",