Skip to content

Commit

Permalink
Merge pull request #1000 from Onlineberatung/fix/api-patch-user-error
Browse files Browse the repository at this point in the history
Add support for handling FETCH_ERRORS.FAILED_DEPENDENCY in apiPatchUs…
  • Loading branch information
janrembold authored Jan 31, 2024
2 parents 96a53e1 + e561422 commit 980ccf0
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/api/apiPatchUserData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ export const apiPatchUserData = async (data): Promise<any> => {
method: FETCH_METHODS.PATCH,
bodyData: JSON.stringify({ ...data }),
rcValidation: true,
responseHandling: [FETCH_ERRORS.BAD_REQUEST]
responseHandling: [
FETCH_ERRORS.BAD_REQUEST,
FETCH_ERRORS.FAILED_DEPENDENCY
]
});
};
8 changes: 8 additions & 0 deletions src/api/fetchData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const FETCH_ERRORS = {
CONFLICT: 'CONFLICT',
CONFLICT_WITH_RESPONSE: 'CONFLICT_WITH_RESPONSE',
EMPTY: 'EMPTY',
FAILED_DEPENDENCY: 'FAILED_DEPENDENCY',
FORBIDDEN: 'FORBIDDEN',
NO_MATCH: 'NO_MATCH',
TIMEOUT: 'TIMEOUT',
Expand Down Expand Up @@ -183,6 +184,13 @@ export const fetchData = ({
? response
: new Error(FETCH_ERRORS.CONFLICT)
);
} else if (
response.status === 424 &&
responseHandling.includes(
FETCH_ERRORS.FAILED_DEPENDENCY
)
) {
reject(new Error(FETCH_ERRORS.FAILED_DEPENDENCY));
} else if (
responseHandling.includes(FETCH_ERRORS.CATCH_ALL) ||
responseHandling.includes(
Expand Down
2 changes: 1 addition & 1 deletion src/components/login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ export const Login = () => {
}

if (Object.keys(patchedUserData).length > 0) {
await apiPatchUserData(patchedUserData);
await apiPatchUserData(patchedUserData).catch(console.log);
await reloadUserData().catch(console.log);
}

Expand Down
17 changes: 14 additions & 3 deletions src/components/profile/ConsultantInformation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
hasUserAuthority,
NotificationsContext,
UserDataContext,
NOTIFICATION_TYPE_SUCCESS
NOTIFICATION_TYPE_SUCCESS,
NOTIFICATION_TYPE_ERROR
} from '../../globalState';
import { Headline } from '../headline/Headline';
import { Text } from '../text/Text';
Expand All @@ -24,6 +25,7 @@ import { useAppConfig } from '../../hooks/useAppConfig';
export const ConsultantInformation = () => {
const { t: translate } = useTranslation();
const { userData, reloadUserData } = useContext(UserDataContext);
const { addNotification } = useContext(NotificationsContext);
const [isEditEnabled, setIsEditEnabled] = useState(false);
const [isSaveDisabled, setIsSaveDisabled] = useState(false);
const [editedDisplayName, setEditedDisplayName] = useState('');
Expand Down Expand Up @@ -53,9 +55,18 @@ export const ConsultantInformation = () => {
.then(() => {
reloadUserData().catch(console.log);
setInitialDisplayName(editedDisplayName);
setIsEditEnabled(false);
})
.catch(() => {
.catch((error) => {
addNotification({
notificationType: NOTIFICATION_TYPE_ERROR,
title: translate('profile.notifications.error.title'),
text: translate('profile.notifications.error.description'),
closeable: true,
timeout: 60000
});
console.error('Error while patching consultant', error);
})
.finally(() => {
setIsEditEnabled(false);
});
};
Expand Down
8 changes: 5 additions & 3 deletions src/components/termsandconditions/TermsAndConditions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,11 @@ export const TermsAndConditions = () => {
userData,
'dataPrivacyConfirmation'
)
}).then(() => {
setViewState({ ...viewState, showOverlay: false });
});
})
.then(() => {
setViewState({ ...viewState, showOverlay: false });
})
.catch(console.log);
};

return (
Expand Down

0 comments on commit 980ccf0

Please sign in to comment.