File
Implements
Index
Properties
|
|
Methods
|
|
Inputs
|
|
setPageTitle
|
Type : boolean
|
Default value : true
|
|
Methods
Private
getBasePath
|
getBasePath()
|
|
|
Private
getFirstPage
|
getFirstPage()
|
|
Returns : Route
|
demandeNotFound
|
Default value : false
|
|
demandeShouldExist
|
Default value : false
|
|
hasSessionExpired
|
Default value : false
|
|
isPendingPayment
|
Type : Observable<boolean>
|
|
supportLink
|
Type : Observable<string>
|
|
wrongEtapeRequested
|
Default value : false
|
|
import { Component, Input, OnInit } from '@angular/core';
import { ActivatedRoute, Route } from '@angular/router';
import { Observable, of } from 'rxjs';
import { catchError, map, tap } from 'rxjs/operators';
import { FoehnNavigationService } from '../foehn-navigation/foehn-navigation.service';
import { FoehnPageService } from '../foehn-page/foehn-page.service';
import {
DEMANDE_NOT_FOUND,
DEMANDE_SHOULD_EXIST,
SESSION_EXPIRED,
WRONG_ETAPE_REQUESTED
} from '../gesdem/gesdem-error-handler.service';
import { GesdemHandlerService } from '../gesdem/gesdem-handler.service';
import { ActionStatut, GesdemStatutUtils } from '../gesdem/gesdem-statut-utils';
import { DemandeHelper } from '../helpers/demande.helper';
import { ApplicationInfoService } from '../sdk-appinfo/application-info.service';
import { SdkDictionaryService } from '../sdk-dictionary/sdk-dictionary.service';
import { SupportAlertService } from '../sdk-support-alert/support-alert.service';
@Component({
// eslint-disable-next-line @angular-eslint/component-selector
selector: 'gesdem-error',
templateUrl: './gesdem-error.component.html'
})
export class GesdemErrorComponent implements OnInit {
@Input()
setPageTitle = true;
link: string;
reference: string;
supportLink: Observable<string>;
hasSessionExpired = false;
demandeShouldExist = false;
wrongEtapeRequested = false;
demandeNotFound = false;
isPendingPayment: Observable<boolean>;
constructor(
private activatedRoute: ActivatedRoute,
private navigation: FoehnNavigationService,
private gesdemService: GesdemHandlerService,
private dictionaryService: SdkDictionaryService,
private foehnPageService: FoehnPageService,
private supportAlertService: SupportAlertService,
private applicationInfoService: ApplicationInfoService
) {
const route = FoehnNavigationService.getRootRouteRecursive(
activatedRoute.snapshot
);
navigation.initRoute(route);
this.link = this.getBasePath();
this.reference =
DemandeHelper.getSafeReference(
this.activatedRoute.snapshot.params.reference
) ||
DemandeHelper.getSafeReference(
this.gesdemService.lastResponse?.meta?.reference
);
this.supportLink = this.applicationInfoService.getSafeSupportFormUrl(
this.reference
);
if (!this.reference?.length) {
this.isPendingPayment = of(false);
} else {
this.isPendingPayment = this.gesdemService
.retrieveActionStatut(this.reference)
.pipe(
tap(statut => {
if (GesdemStatutUtils.isFinal(statut)) {
this.navigation.last();
}
}),
map(statut => statut === ActionStatut.PENDING_PAYMENT),
catchError(() => of(false))
);
}
}
ngOnInit(): void {
if (this.reference) {
const firstPage = this.getFirstPage();
if (this.gesdemService.prefix) {
this.link += `${this.gesdemService.prefix}/`;
}
this.link += `${this.reference}/${firstPage.path}`;
const errorCode =
this.activatedRoute.snapshot.queryParamMap.get('errorCode');
this.hasSessionExpired = errorCode === SESSION_EXPIRED;
this.demandeShouldExist = errorCode === DEMANDE_SHOULD_EXIST;
this.wrongEtapeRequested = errorCode === WRONG_ETAPE_REQUESTED;
this.demandeNotFound = errorCode === DEMANDE_NOT_FOUND;
}
// The error might have been caused by an issue with the prestation that has been identified
// whilst the user is using the prestation. This ensures that if any alert is added by the
// administrator, the user will at least see them if an error is shown.
this.supportAlertService.refreshAlerts();
if (this.setPageTitle) {
this.foehnPageService.setPageTitle(
this.dictionaryService.getKeySync(
this.hasSessionExpired
? 'gesdem-error.title.recovery'
: 'gesdem-error.title.error'
)
);
}
}
private getFirstPage(): Route {
return this.navigation.getFirstRoute();
}
private getBasePath(): string {
const base = document.getElementsByTagName('base');
if (base.length === 1) {
return base[0].href;
}
return '/';
}
}
<div class="vd-card mb-3" *ngIf="!hasSessionExpired">
<div class="container">
<div class="row">
<div class="col-xs-8">
<div class="card-body">
@if (wrongEtapeRequested || demandeNotFound) {
<p
class="card-text vd-card-text alert alert-danger"
[innerHTML]="
(wrongEtapeRequested
? 'gesdem-error.text.wrong-etape-requested'
: 'gesdem-error.text.demande-not-found'
) | fromDictionary: { reference }
"
></p>
} @else if ((isPendingPayment | async) === true) {
<p
class="card-text vd-card-text alert alert-danger"
[innerHTML]="
'gesdem-error.text.pending-payment'
| fromDictionary
: { supportLink: (supportLink | async) }
"
></p>
} @else {
@if (demandeShouldExist) {
<p
class="card-text vd-card-text"
[innerHTML]="
'gesdem-error.demande-should-exist'
| fromDictionary
"
></p>
<ul class="vd-list-links">
<li>
<a
[href]="link"
[innerHTML]="
'gesdem-error.link.has-no-reference'
| fromDictionary
"
></a>
</li>
</ul>
} @else {
<p class="card-text vd-card-text">
{{
(!!reference
? 'gesdem-error.text.has-reference'
: 'gesdem-error.text.has-no-reference'
) | fromDictionary
}}
</p>
<ul class="vd-list-links">
<li>
<a [href]="link">
{{
(!!reference
? 'gesdem-error.link.has-reference'
: 'gesdem-error.link.has-no-reference'
) | fromDictionary
}}
</a>
</li>
</ul>
}
}
<foehn-debug-summary
*ngIf="!demandeNotFound && !wrongEtapeRequested"
></foehn-debug-summary>
</div>
</div>
</div>
</div>
</div>
<gesdem-action-recovery-login
*ngIf="hasSessionExpired"
[reference]="reference"
[redirectTarget]="link"
></gesdem-action-recovery-login>
Legend
Html element with directive