Elffuss BraidHub

kikocis/dataspace-portal public

fix: vague error message on 409 from KC (#312)

Changeset41f7e041006864a8d4cf7beddce8a785ac7b1cd8aec3d60954da7efe24283ef5
AuthorKamil Czaja <46053356+kamilczaja@users.noreply.github.com> · 2024-09-12 15:30 +02:00
CommitterGitHub <noreply@github.com> · 2024-09-12 15:30 +02:00
Parents6d7191967870

Browse the files at this changeset

5 files changed

modified CHANGELOG.md +1 −0
@@ -19,6 +19,7 @@
1919 - Adjusted data source availability naming in the CSV report
2020 - `LIVE` -> `Available`
2121 - `ON_REQUEST` -> `On Request`
22+- Changed the error message on user/organization invite failures to be more descriptive
2223
2324 ### Known issues
2425
modified authority-portal-frontend/src/app/core/services/error.service.ts +17 −0
@@ -36,4 +36,21 @@
3636 return EMPTY;
3737 });
3838 }
39+
40+ toastRegistrationErrorRxjs<T>(
41+ genericFailureMessage: string,
42+ onError?: () => void,
43+ ): MonoTypeOperatorFunction<T> {
44+ return catchError((err) => {
45+ let errorMessage = genericFailureMessage;
46+ if (err?.response?.status === 409) {
47+ errorMessage = 'A user with this email address already exists.';
48+ }
49+ this.toastFailure(errorMessage);
50+ if (onError) {
51+ onError();
52+ }
53+ return EMPTY;
54+ });
55+ }
3956 }
modified authority-portal-frontend/src/app/pages/authority-organization-list-page/authority-invite-new-organization/state/authority-invite-new-organization-page-state-impl.ts +9 −6
@@ -22,9 +22,9 @@
2222 ofAction,
2323 } from '@ngxs/store';
2424 import {ApiService} from 'src/app/core/api/api.service';
25-import {ErrorService} from 'src/app/core/services/error.service';
2625 import {RefreshOrganizations} from 'src/app/pages/authority-organization-list-page/authority-organization-list-page/state/authority-organization-list-page-actions';
2726 import {ToastService} from 'src/app/shared/common/toast-notifications/toast.service';
27+import {ErrorService} from '../../../../core/services/error.service';
2828 import {
2929 InviteNewOrganization,
3030 Reset,
@@ -44,8 +44,8 @@
4444 private apiService: ApiService,
4545 private toast: ToastService,
4646 private actions$: Actions,
47- private errorService: ErrorService,
4847 private store: Store,
48+ private errorService: ErrorService,
4949 ) {}
5050
5151 @Action(Reset)
@@ -69,10 +69,13 @@
6969 this.store.dispatch(RefreshOrganizations);
7070 }),
7171 takeUntil(this.actions$.pipe(ofAction(Reset))),
72- this.errorService.toastFailureRxjs('Failed Inviting Organization', () => {
73- ctx.patchState({state: 'error'});
74- action.enableForm();
75- }),
72+ this.errorService.toastRegistrationErrorRxjs(
73+ 'Failed inviting organization due to an unknown error.',
74+ () => {
75+ ctx.patchState({state: 'error'});
76+ action.enableForm();
77+ },
78+ ),
7679 ignoreElements(),
7780 );
7881 }
modified authority-portal-frontend/src/app/pages/control-center-organization-members-page/participant-invite-new-user/state/participant-invite-new-user-page-state-impl.ts +8 −5
@@ -15,8 +15,8 @@
1515 import {ignoreElements, takeUntil, tap} from 'rxjs/operators';
1616 import {Action, Actions, State, StateContext, ofAction} from '@ngxs/store';
1717 import {ApiService} from 'src/app/core/api/api.service';
18-import {ErrorService} from 'src/app/core/services/error.service';
1918 import {ToastService} from 'src/app/shared/common/toast-notifications/toast.service';
19+import {ErrorService} from '../../../../core/services/error.service';
2020 import {InviteNewUser, Reset} from './participant-invite-new-user-page-actions';
2121 import {
2222 DEFAULT_PARTICIPANT_INVITE_NEW_USER_PAGE_STATE,
@@ -50,10 +50,6 @@
5050 action.disableForm();
5151 return this.apiService.inviteUser(action.request).pipe(
5252 takeUntil(this.actions$.pipe(ofAction(Reset))),
53- this.errorService.toastFailureRxjs('Failed Inviting User', () => {
54- ctx.patchState({state: 'error'});
55- action.enableForm();
56- }),
5753 tap(() => {
5854 this.toast.showSuccess(
5955 `The invitation for ${action.request.firstName} ${action.request.lastName} was sent.`,
@@ -61,6 +57,13 @@
6157 ctx.patchState({state: 'success'});
6258 action.success();
6359 }),
60+ this.errorService.toastRegistrationErrorRxjs(
61+ 'Failed inviting user due to an unknown error.',
62+ () => {
63+ ctx.patchState({state: 'error'});
64+ action.enableForm();
65+ },
66+ ),
6467 ignoreElements(),
6568 );
6669 }
modified authority-portal-frontend/src/app/pages/registration-pages/organization-create-page/state/organization-create-page-state-impl.ts +10 −13
@@ -11,12 +11,13 @@
1111 * sovity GmbH - initial implementation
1212 */
1313 import {Inject, Injectable} from '@angular/core';
14-import {Observable, of} from 'rxjs';
14+import {EMPTY, Observable, of} from 'rxjs';
1515 import {catchError, ignoreElements, takeUntil, tap} from 'rxjs/operators';
1616 import {Action, Actions, State, StateContext, ofAction} from '@ngxs/store';
1717 import {ApiService} from 'src/app/core/api/api.service';
1818 import {APP_CONFIG, AppConfig} from 'src/app/core/services/config/app-config';
1919 import {ToastService} from 'src/app/shared/common/toast-notifications/toast.service';
20+import {ErrorService} from '../../../../core/services/error.service';
2021 import {CreateOrganization, Reset} from './organization-create-page-action';
2122 import {
2223 DEFAULT_ORGANIZATION_REGISTRATION_PAGE_STATE,
@@ -34,6 +35,7 @@
3435 private apiService: ApiService,
3536 private toast: ToastService,
3637 private actions$: Actions,
38+ private errorService: ErrorService,
3739 ) {}
3840
3941 @Action(Reset)
@@ -57,18 +59,13 @@
5759 action.success();
5860 }),
5961 takeUntil(this.actions$.pipe(ofAction(Reset))),
60- catchError((err) => {
61- let errorMessage = 'Registration failed due to an unknown error.';
62- console.log(err);
63- console.log(err.status);
64- if (err?.response?.status === 409) {
65- errorMessage = 'This e-mail address is already registered.';
66- }
67- this.toast.showDanger(errorMessage);
68- ctx.patchState({state: 'error'});
69- action.enableForm();
70- return of(null);
71- }),
62+ this.errorService.toastRegistrationErrorRxjs(
63+ 'Registration failed due to an unknown error',
64+ () => {
65+ ctx.patchState({state: 'error'});
66+ action.enableForm();
67+ },
68+ ),
7269 ignoreElements(),
7370 );
7471 }