Skip to content

Commit

Permalink
Merge pull request #1797 from France-ioi/fix-too-many-redirections
Browse files Browse the repository at this point in the history
Fix too many redirections
  • Loading branch information
smadbe authored Oct 1, 2024
2 parents 41acc67 + 1f72275 commit 1531193
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ module.exports = {
'ignoreStatic': true
}],
'@typescript-eslint/no-explicit-any': 'off',
'@ngrx/no-store-subscription': 'off'
},
overrides: [
{
Expand Down
17 changes: 9 additions & 8 deletions src/app/items/item-by-id.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ export class ItemByIdComponent implements OnDestroy, BeforeUnloadComponent, Pend
this.itemRouter.navigateTo({ ...route, answer: undefined });
}),

// eslint-disable-next-line @ngrx/no-store-subscription
this.store.select(fromItemContent.selectActiveContentRoute).subscribe(route => {
if (route) {
// just publish to current content the new route we are navigating to (without knowing any info)
Expand All @@ -239,7 +238,6 @@ export class ItemByIdComponent implements OnDestroy, BeforeUnloadComponent, Pend

// on datasource state change, update the current content page info
this.itemState$.pipe(readyData()).subscribe(data => {
this.hasRedirected = false;
this.currentContent.replace(itemInfo({
breadcrumbs: {
category: itemBreadcrumbCat,
Expand Down Expand Up @@ -268,18 +266,21 @@ export class ItemByIdComponent implements OnDestroy, BeforeUnloadComponent, Pend

this.breadcrumbService.resultPathStarted$.subscribe(() => this.currentContent.forceNavMenuReload()),

this.itemState$.pipe(
filter(s => s.isError),
).subscribe(state => {
this.store.select(fromItemContent.selectActiveContentBreadcrumbs).subscribe(state => {
if (state.isError) this.currentContent.clear();

// If path is incorrect, redirect to same page without path to trigger the solve missing path at next navigation
if (errorHasTag(state.error, breadcrumbServiceTag) && (errorIsHTTPForbidden(state.error) || errorIsHTTPNotFound(state.error))) {
if (
state.isError &&
errorHasTag(state.error, breadcrumbServiceTag) &&
(errorIsHTTPForbidden(state.error) || errorIsHTTPNotFound(state.error))
) {
if (this.hasRedirected) throw new Error('Too many redirections (unexpected)');
this.hasRedirected = true;
const { contentType, id, answer } = this.getItemRoute();
if (!id) throw new Error('Unexpected: item id should exist');
this.itemRouter.navigateTo({ contentType, id, answer }, { navExtras: { replaceUrl: true } });
}
this.currentContent.clear();
} else this.hasRedirected = false;
}),

combineLatest([ this.itemRoute$, this.itemState$.pipe(startWith(undefined)) ]).pipe(
Expand Down
1 change: 0 additions & 1 deletion src/app/services/crash-reporting.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export class CrashReportingService {
init(): void {
this.userSessionService.session$.subscribe(session => setUser(session ? { id: session.groupId, username: session.login } : null));

// eslint-disable-next-line @ngrx/no-store-subscription
this.store.select(fromObservation.selectObservedGroupId).subscribe(g => addBreadcrumb({
category: 'group-watching',
level: 'info',
Expand Down

0 comments on commit 1531193

Please sign in to comment.