Skip to content

refactor/AB#82357_create-shared-error-handler-logic-for-the-app #2434

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: refactor/AB#82357_update-angular-fix-memory-leak-issues-and-other-fixes
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,20 @@ export class DashboardComponent
this.widgets = cloneDeep(
data.dashboard.structure ? data.dashboard.structure : []
);
this.loading = loading;
} else {
this.snackBar.openSnackBar(
this.translate.instant(
'common.notifications.accessNotProvided',
{
type: this.translate
.instant('common.dashboard.one')
.toLowerCase(),
error: '',
}
),
{ error: true }
);
this.router.navigate(['/dashboards']);
}
this.loading = loading;
},
error: (err) => {
this.snackBar.openSnackBar(err.message, { error: true });
error: () => {
this.loading = false;
this.snackBar.openSnackBar(
this.translate.instant('common.notifications.accessNotProvided', {
type: this.translate
.instant('common.dashboard.one')
.toLowerCase(),
error: '',
}),
{ error: true }
);
this.router.navigate(['/dashboards']);
},
});
Expand Down
26 changes: 18 additions & 8 deletions apps/back-office/src/app/app-preview/pages/form/form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,14 @@ export class FormComponent extends UnsubscribeComponent implements OnInit {
});
})
)
.subscribe(({ data, loading }) => {
this.form = data.form;
this.loading = loading;
.subscribe({
next: ({ data, loading }) => {
this.form = data.form;
this.loading = loading;
},
error: () => {
this.loading = false;
},
});
} else {
this.apollo
Expand All @@ -119,11 +124,16 @@ export class FormComponent extends UnsubscribeComponent implements OnInit {
});
})
)
.subscribe(({ data, loading }) => {
if (data) {
this.form = data.form;
}
this.loading = loading;
.subscribe({
next: ({ data, loading }) => {
if (data) {
this.form = data.form;
}
this.loading = loading;
},
error: () => {
this.loading = false;
},
});
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,17 @@ export class WorkflowComponent extends UnsubscribeComponent implements OnInit {
if (this.steps.length > 0) {
this.onOpenStep(0);
}
} else {
this.snackBar.openSnackBar(
this.translate.instant('common.notifications.accessNotProvided', {
type: this.translate
.instant('common.workflow.one')
.toLowerCase(),
error: '',
}),
{ error: true }
);
}
},
error: (err) => {
this.snackBar.openSnackBar(err.message, { error: true });
error: () => {
this.loading = false;
this.snackBar.openSnackBar(
this.translate.instant('common.notifications.accessNotProvided', {
type: this.translate.instant('common.workflow.one').toLowerCase(),
error: '',
}),
{ error: true }
);
},
});
}
Expand Down
6 changes: 6 additions & 0 deletions apps/back-office/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
AppAbility,
FormService,
DatePipe,
ErrorHandlerInterceptorService,
} from '@oort-front/shared';
import { registerLocaleData } from '@angular/common';
import localeFr from '@angular/common/locales/fr';
Expand Down Expand Up @@ -146,6 +147,11 @@ export const httpTranslateLoader = (http: HttpClient) =>
useClass: AuthInterceptorService,
multi: true,
},
{
provide: HTTP_INTERCEPTORS,
useClass: ErrorHandlerInterceptorService,
multi: true,
},
{
provide: AppAbility,
useValue: new AppAbility(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
UnsubscribeComponent,
FormsQueryResponse,
AddFormMutationResponse,
errorMessageFormatter,
} from '@oort-front/shared';
import { takeUntil } from 'rxjs';
import { ADD_FORM } from './graphql/mutations';
Expand Down Expand Up @@ -180,35 +181,31 @@ export class AddPageComponent extends UnsubscribeComponent implements OnInit {
variables: variablesData,
})
.subscribe({
next: ({ errors, data }) => {
if (errors) {
this.snackBar.openSnackBar(
this.translate.instant(
'common.notifications.objectNotCreated',
{
type: this.translate
.instant('common.form.one')
.toLowerCase(),
error: errors ? errors[0].message : '',
}
),
{ error: true }
);
} else {
const id = data?.addForm.id || '';
this.pageForm.controls.content.setValue(id);
this.snackBar.openSnackBar(
this.translate.instant('common.notifications.objectCreated', {
type: this.translate.instant('common.page.one'),
value: value.name,
})
);
next: ({ data }) => {
const id = data?.addForm.id || '';
this.pageForm.controls.content.setValue(id);
this.snackBar.openSnackBar(
this.translate.instant('common.notifications.objectCreated', {
type: this.translate.instant('common.page.one'),
value: value.name,
})
);

this.onSubmit();
}
this.onSubmit();
},
error: (err) => {
this.snackBar.openSnackBar(err.message, { error: true });
error: (errors) => {
this.snackBar.openSnackBar(
this.translate.instant(
'common.notifications.objectNotCreated',
{
type: this.translate
.instant('common.form.one')
.toLowerCase(),
error: errorMessageFormatter(errors),
}
),
{ error: true }
);
},
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,18 @@ export class ArchiveComponent extends UnsubscribeComponent implements OnInit {
autoDeletedAt: page.autoDeletedAt,
} as ArchivePage;
}) ?? [];
} else {
this.snackBar.openSnackBar(
this.translate.instant('common.notifications.accessNotProvided', {
type: this.translate
.instant('common.workflow.one')
.toLowerCase(),
error: '',
}),
{ error: true }
);
}
this.loading = false;
},
error: (err) => {
this.snackBar.openSnackBar(err.message, { error: true });
error: () => {
this.loading = false;
this.snackBar.openSnackBar(
this.translate.instant('common.notifications.accessNotProvided', {
type: this.translate.instant('common.workflow.one').toLowerCase(),
error: '',
}),
{ error: true }
);
},
});
}
Expand Down
29 changes: 17 additions & 12 deletions apps/back-office/src/app/application/pages/form/form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,23 @@ export class FormComponent extends UnsubscribeComponent implements OnInit {
}),
takeUntil(this.destroy$)
)
.subscribe((res: any) => {
// If a query is already loading, cancel it
if (this.querySubscription) {
this.querySubscription.unsubscribe();
}
if (this.isStep) {
this.handleFormQueryResponse(res.data, 'step');
this.loading = res.loading;
} else {
this.handleFormQueryResponse(res.data, 'page');
this.loading = res.loading;
}
.subscribe({
next: (res: any) => {
// If a query is already loading, cancel it
if (this.querySubscription) {
this.querySubscription.unsubscribe();
}
if (this.isStep) {
this.handleFormQueryResponse(res.data, 'step');
this.loading = res.loading;
} else {
this.handleFormQueryResponse(res.data, 'page');
this.loading = res.loading;
}
},
error: () => {
this.loading = false;
},
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,22 @@ export class PositionAttributesComponent implements OnInit {
id: this.id,
},
})
.subscribe(({ data, loading }) => {
this.positionAttributes = data.positionAttributes;
if (this.positionAttributes.length > 0) {
this.categoryName = this.positionAttributes[0].category?.title || '';
this.breadcrumbService.setBreadcrumb('@attribute', this.categoryName);
}
this.loading = loading;
.subscribe({
next: ({ data, loading }) => {
this.positionAttributes = data.positionAttributes;
if (this.positionAttributes.length > 0) {
this.categoryName =
this.positionAttributes[0].category?.title || '';
this.breadcrumbService.setBreadcrumb(
'@attribute',
this.categoryName
);
}
this.loading = loading;
},
error: () => {
this.loading = false;
},
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
UnsubscribeComponent,
DeleteApplicationMutationResponse,
status,
errorMessageFormatter,
} from '@oort-front/shared';
import { Dialog } from '@angular/cdk/dialog';
import { DELETE_APPLICATION } from './graphql/mutations';
Expand Down Expand Up @@ -168,28 +169,21 @@ export class SettingsComponent extends UnsubscribeComponent implements OnInit {
takeUntil(this.destroy$)
)
.subscribe({
next: ({ errors }) => {
if (errors) {
this.snackBar.openSnackBar(
this.translate.instant(
'common.notifications.objectNotDeleted',
{
value: this.translate.instant('common.application.one'),
error: errors ? errors[0].message : '',
}
),
{ error: true }
);
} else {
this.snackBar.openSnackBar(
this.translate.instant('common.notifications.objectDeleted', {
value: this.translate.instant('common.application.one'),
})
);
}
next: () => {
this.snackBar.openSnackBar(
this.translate.instant('common.notifications.objectDeleted', {
value: this.translate.instant('common.application.one'),
})
);
},
error: (err) => {
this.snackBar.openSnackBar(err.message, { error: true });
error: (errors) => {
this.snackBar.openSnackBar(
this.translate.instant('common.notifications.objectNotDeleted', {
value: this.translate.instant('common.application.one'),
error: errorMessageFormatter(errors),
}),
{ error: true }
);
},
complete: () => this.router.navigate(['/applications']),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,13 @@ export class SubscriptionModalComponent
// this.applications$ = this.applications.asObservable();
this.applicationsQuery.valueChanges
.pipe(takeUntil(this.destroy$))
.subscribe((results) => {
this.updateValues(results.data, results.loading);
.subscribe({
next: (results) => {
this.updateValues(results.data, results.loading);
},
error: () => {
this.applicationsLoading = false;
},
});

this.formsQuery = this.apollo.watchQuery<FormsQueryResponse>({
Expand Down
Loading