mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-15 05:53:03 +00:00
[DSC-287] Created new page error 500, added guard to check for initial api request, redirect to page 500
This commit is contained in:
@@ -89,6 +89,12 @@ export function getPageNotFoundRoute() {
|
||||
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 function getInfoModulePath() {
|
||||
return `/${INFO_MODULE_PATH}`;
|
||||
|
@@ -26,6 +26,9 @@ import { SiteRegisterGuard } from './core/data/feature-authorization/feature-aut
|
||||
import { ThemedPageNotFoundComponent } from './pagenotfound/themed-pagenotfound.component';
|
||||
import { ThemedForbiddenComponent } from './forbidden/themed-forbidden.component';
|
||||
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({
|
||||
imports: [
|
||||
@@ -33,157 +36,160 @@ import { GroupAdministratorGuard } from './core/data/feature-authorization/featu
|
||||
path: '', canActivate: [AuthBlockingGuard],
|
||||
children: [
|
||||
{ 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',
|
||||
loadChildren: () => import('./home-page/home-page.module')
|
||||
.then((m) => m.HomePageModule),
|
||||
data: { showBreadcrumbs: false },
|
||||
canActivate: [EndUserAgreementCurrentUserGuard]
|
||||
canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard]
|
||||
},
|
||||
{
|
||||
path: 'community-list',
|
||||
loadChildren: () => import('./community-list-page/community-list-page.module')
|
||||
.then((m) => m.CommunityListPageModule),
|
||||
canActivate: [EndUserAgreementCurrentUserGuard]
|
||||
canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard]
|
||||
},
|
||||
{
|
||||
path: 'id',
|
||||
loadChildren: () => import('./lookup-by-id/lookup-by-id.module')
|
||||
.then((m) => m.LookupIdModule),
|
||||
canActivate: [EndUserAgreementCurrentUserGuard]
|
||||
canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard]
|
||||
},
|
||||
{
|
||||
path: 'handle',
|
||||
loadChildren: () => import('./lookup-by-id/lookup-by-id.module')
|
||||
.then((m) => m.LookupIdModule),
|
||||
canActivate: [EndUserAgreementCurrentUserGuard]
|
||||
canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard]
|
||||
},
|
||||
{
|
||||
path: REGISTER_PATH,
|
||||
loadChildren: () => import('./register-page/register-page.module')
|
||||
.then((m) => m.RegisterPageModule),
|
||||
canActivate: [SiteRegisterGuard]
|
||||
canActivate: [ServerCheckGuard, SiteRegisterGuard]
|
||||
},
|
||||
{
|
||||
path: FORGOT_PASSWORD_PATH,
|
||||
loadChildren: () => import('./forgot-password/forgot-password.module')
|
||||
.then((m) => m.ForgotPasswordModule),
|
||||
canActivate: [EndUserAgreementCurrentUserGuard]
|
||||
canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard]
|
||||
},
|
||||
{
|
||||
path: COMMUNITY_MODULE_PATH,
|
||||
loadChildren: () => import('./community-page/community-page.module')
|
||||
.then((m) => m.CommunityPageModule),
|
||||
canActivate: [EndUserAgreementCurrentUserGuard]
|
||||
canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard]
|
||||
},
|
||||
{
|
||||
path: COLLECTION_MODULE_PATH,
|
||||
loadChildren: () => import('./collection-page/collection-page.module')
|
||||
.then((m) => m.CollectionPageModule),
|
||||
canActivate: [EndUserAgreementCurrentUserGuard]
|
||||
canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard]
|
||||
},
|
||||
{
|
||||
path: ITEM_MODULE_PATH,
|
||||
loadChildren: () => import('./item-page/item-page.module')
|
||||
.then((m) => m.ItemPageModule),
|
||||
canActivate: [EndUserAgreementCurrentUserGuard]
|
||||
canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard]
|
||||
},
|
||||
{ path: 'entities/:entity-type',
|
||||
loadChildren: () => import('./item-page/item-page.module')
|
||||
.then((m) => m.ItemPageModule),
|
||||
canActivate: [EndUserAgreementCurrentUserGuard]
|
||||
canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard]
|
||||
},
|
||||
{
|
||||
path: LEGACY_BITSTREAM_MODULE_PATH,
|
||||
loadChildren: () => import('./bitstream-page/bitstream-page.module')
|
||||
.then((m) => m.BitstreamPageModule),
|
||||
canActivate: [EndUserAgreementCurrentUserGuard]
|
||||
canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard]
|
||||
},
|
||||
{
|
||||
path: BITSTREAM_MODULE_PATH,
|
||||
loadChildren: () => import('./bitstream-page/bitstream-page.module')
|
||||
.then((m) => m.BitstreamPageModule),
|
||||
canActivate: [EndUserAgreementCurrentUserGuard]
|
||||
canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard]
|
||||
},
|
||||
{
|
||||
path: 'mydspace',
|
||||
loadChildren: () => import('./my-dspace-page/my-dspace-page.module')
|
||||
.then((m) => m.MyDSpacePageModule),
|
||||
canActivate: [AuthenticatedGuard, EndUserAgreementCurrentUserGuard]
|
||||
canActivate: [ServerCheckGuard, AuthenticatedGuard, EndUserAgreementCurrentUserGuard]
|
||||
},
|
||||
{
|
||||
path: 'search',
|
||||
loadChildren: () => import('./search-page/search-page-routing.module')
|
||||
.then((m) => m.SearchPageRoutingModule),
|
||||
canActivate: [EndUserAgreementCurrentUserGuard]
|
||||
canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard]
|
||||
},
|
||||
{
|
||||
path: 'browse',
|
||||
loadChildren: () => import('./browse-by/browse-by-page.module')
|
||||
.then((m) => m.BrowseByPageModule),
|
||||
canActivate: [EndUserAgreementCurrentUserGuard]
|
||||
canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard]
|
||||
},
|
||||
{
|
||||
path: ADMIN_MODULE_PATH,
|
||||
loadChildren: () => import('./admin/admin.module')
|
||||
.then((m) => m.AdminModule),
|
||||
canActivate: [SiteAdministratorGuard, EndUserAgreementCurrentUserGuard]
|
||||
canActivate: [ServerCheckGuard, SiteAdministratorGuard, EndUserAgreementCurrentUserGuard]
|
||||
},
|
||||
{
|
||||
path: 'login',
|
||||
loadChildren: () => import('./login-page/login-page.module')
|
||||
.then((m) => m.LoginPageModule),
|
||||
canActivate: [ServerCheckGuard]
|
||||
},
|
||||
{
|
||||
path: 'logout',
|
||||
loadChildren: () => import('./logout-page/logout-page.module')
|
||||
.then((m) => m.LogoutPageModule),
|
||||
canActivate: [ServerCheckGuard]
|
||||
},
|
||||
{
|
||||
path: 'submit',
|
||||
loadChildren: () => import('./submit-page/submit-page.module')
|
||||
.then((m) => m.SubmitPageModule),
|
||||
canActivate: [EndUserAgreementCurrentUserGuard]
|
||||
canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard]
|
||||
},
|
||||
{
|
||||
path: 'import-external',
|
||||
loadChildren: () => import('./import-external-page/import-external-page.module')
|
||||
.then((m) => m.ImportExternalPageModule),
|
||||
canActivate: [EndUserAgreementCurrentUserGuard]
|
||||
canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard]
|
||||
},
|
||||
{
|
||||
path: 'workspaceitems',
|
||||
loadChildren: () => import('./workspaceitems-edit-page/workspaceitems-edit-page.module')
|
||||
.then((m) => m.WorkspaceitemsEditPageModule),
|
||||
canActivate: [EndUserAgreementCurrentUserGuard]
|
||||
canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard]
|
||||
},
|
||||
{
|
||||
path: WORKFLOW_ITEM_MODULE_PATH,
|
||||
loadChildren: () => import('./workflowitems-edit-page/workflowitems-edit-page.module')
|
||||
.then((m) => m.WorkflowItemsEditPageModule),
|
||||
canActivate: [EndUserAgreementCurrentUserGuard]
|
||||
canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard]
|
||||
},
|
||||
{
|
||||
path: PROFILE_MODULE_PATH,
|
||||
loadChildren: () => import('./profile-page/profile-page.module')
|
||||
.then((m) => m.ProfilePageModule),
|
||||
canActivate: [AuthenticatedGuard, EndUserAgreementCurrentUserGuard]
|
||||
canActivate: [ServerCheckGuard, AuthenticatedGuard, EndUserAgreementCurrentUserGuard]
|
||||
},
|
||||
{
|
||||
path: PROCESS_MODULE_PATH,
|
||||
loadChildren: () => import('./process-page/process-page.module')
|
||||
.then((m) => m.ProcessPageModule),
|
||||
canActivate: [AuthenticatedGuard, EndUserAgreementCurrentUserGuard]
|
||||
canActivate: [ServerCheckGuard, AuthenticatedGuard, EndUserAgreementCurrentUserGuard]
|
||||
},
|
||||
{
|
||||
path: INFO_MODULE_PATH,
|
||||
loadChildren: () => import('./info/info.module').then((m) => m.InfoModule),
|
||||
canActivate: [ServerCheckGuard]
|
||||
},
|
||||
{
|
||||
path: REQUEST_COPY_MODULE_PATH,
|
||||
loadChildren: () => import('./request-copy/request-copy.module').then((m) => m.RequestCopyModule),
|
||||
canActivate: [AuthenticatedGuard, EndUserAgreementCurrentUserGuard]
|
||||
canActivate: [ServerCheckGuard, AuthenticatedGuard, EndUserAgreementCurrentUserGuard]
|
||||
},
|
||||
{
|
||||
path: FORBIDDEN_PATH,
|
||||
@@ -193,12 +199,14 @@ import { GroupAdministratorGuard } from './core/data/feature-authorization/featu
|
||||
path: 'statistics',
|
||||
loadChildren: () => import('./statistics-page/statistics-page-routing.module')
|
||||
.then((m) => m.StatisticsPageRoutingModule),
|
||||
canActivate: [ServerCheckGuard]
|
||||
},
|
||||
{
|
||||
path: ACCESS_CONTROL_MODULE_PATH,
|
||||
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 },
|
||||
]}
|
||||
],{
|
||||
|
@@ -53,6 +53,8 @@ import { ThemedFooterComponent } from './footer/themed-footer.component';
|
||||
import { ThemedBreadcrumbsComponent } from './breadcrumbs/themed-breadcrumbs.component';
|
||||
import { ThemedHeaderNavbarWrapperComponent } from './header-nav-wrapper/themed-header-navbar-wrapper.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 { CookieService } from './core/services/cookie.service';
|
||||
@@ -187,7 +189,9 @@ const DECLARATIONS = [
|
||||
ThemedBreadcrumbsComponent,
|
||||
ForbiddenComponent,
|
||||
ThemedForbiddenComponent,
|
||||
IdleModalComponent
|
||||
IdleModalComponent,
|
||||
ThemedPageInternalServerErrorComponent,
|
||||
PageInternalServerErrorComponent
|
||||
];
|
||||
|
||||
const EXPORTS = [
|
||||
|
16
src/app/core/server-check/server-check.guard.spec.ts
Normal file
16
src/app/core/server-check/server-check.guard.spec.ts
Normal 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();
|
||||
});
|
||||
});
|
30
src/app/core/server-check/server-check.guard.ts
Normal file
30
src/app/core/server-check/server-check.guard.ts
Normal 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());
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
}
|
||||
}
|
@@ -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>
|
@@ -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();
|
||||
}
|
||||
|
||||
}
|
@@ -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`);
|
||||
}
|
||||
}
|
@@ -14,6 +14,11 @@
|
||||
|
||||
"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. ",
|
||||
|
Reference in New Issue
Block a user