Skip to content
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

bug/115476 error message #846

Merged
merged 3 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -30,13 +30,13 @@ import { Organization } from '../../types';
import { OrganizationMap } from '../utils';
import { SelectItem } from '@procosys/components/Select';
import { poTypes } from './GeneralInfo/GeneralInfo';
import { showSnackbarNotification } from '@procosys/core/services/NotificationService';
import { useAnalytics } from '@procosys/core/services/Analytics/AnalyticsContext';
import { useDirtyContext } from '@procosys/core/DirtyContext';
import { useInvitationForPunchOutContext } from '../../context/InvitationForPunchOutContext';
import { useParams } from 'react-router-dom';
import useRouter from '@procosys/hooks/useRouter';
import { set } from 'date-fns';
import { handleApiError } from './utils';

const emptyGeneralInfo: GeneralInfoDetails = {
projectName: '',
Expand Down Expand Up @@ -187,13 +187,7 @@ const EditIPO = (): JSX.Element => {
);
setAvailableRoles(functionalRoles);
} catch (error) {
if (!(error instanceof IpoApiError)) {
console.error(error);
showSnackbarNotification('Unknown error');
return;
}
console.error(error.message, error.data);
showSnackbarNotification(error.message);
handleApiError(error);
}
},
[params.ipoId]
Expand Down Expand Up @@ -299,17 +293,10 @@ const EditIPO = (): JSX.Element => {
);
}
} catch (error) {
if (!(error instanceof IpoApiError)) {
console.error(error);
showSnackbarNotification('Unknown error');
return;
}
console.error(
'Upload or delete of attachment failed: ',
error.message,
error.data
handleApiError(
error,
'Upload or delete of attachment failed'
);
showSnackbarNotification(error.message);
}
})
);
Expand All @@ -325,13 +312,7 @@ const EditIPO = (): JSX.Element => {
);
setAttachments(response);
} catch (error) {
if (!(error instanceof IpoApiError)) {
console.error(error);
showSnackbarNotification('Unknown error');
return;
}
console.error(error.message, error.data);
showSnackbarNotification(error.message);
handleApiError(error);
}
};

Expand Down Expand Up @@ -398,17 +379,7 @@ const EditIPO = (): JSX.Element => {
]);
history.push('/' + params.ipoId);
} catch (error) {
if (!(error instanceof IpoApiError)) {
console.error(error);
showSnackbarNotification('Unknown error');
return;
}
console.error(
'Save updated IPO failed: ',
error.message,
error.data
);
showSnackbarNotification(error.message);
handleApiError(error, 'Save updated IPO failed: ');
}
}
setIsSaving(false);
Expand All @@ -425,13 +396,7 @@ const EditIPO = (): JSX.Element => {
);
setInvitation(response);
} catch (error) {
if (!(error instanceof IpoApiError)) {
console.error(error);
showSnackbarNotification('Unknown error');
return;
}
console.error(error.message, error.data);
showSnackbarNotification(error.message);
handleApiError(error);
}
},
[params.ipoId]
Expand Down
14 changes: 14 additions & 0 deletions src/modules/InvitationForPunchOut/views/CreateAndEditIPO/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { addDays, addHours, addMinutes, set } from 'date-fns';

import { Attachment } from '../../types';
import { IpoApiError } from '../../http/InvitationForPunchOutApiClient';
import { showSnackbarNotification } from '@procosys/core/services/NotificationService';

export const getEndTime = (date: Date): Date => {
if (date.getHours() === 23) {
Expand Down Expand Up @@ -45,3 +47,15 @@ export const getAttachmentDownloadLink = (

return undefined;
};

export const handleApiError = (error: any, customMessage?: string): void => {
if (!(error instanceof IpoApiError)) {
console.error(error);
showSnackbarNotification(
error.message || customMessage || 'Unknown error'
);
} else {
console.error(error.message, error.data);
showSnackbarNotification(error.message);
}
};
Loading