Skip to content

Commit

Permalink
fix: #735 error handling fix (#746)
Browse files Browse the repository at this point in the history
Co-authored-by: Nicola Saglioni <nicola.saglioni@encora.com>
  • Loading branch information
NickSaglioni and NickSaglioni authored Aug 24, 2023
1 parent ed72388 commit 5d2a709
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 92 deletions.
50 changes: 0 additions & 50 deletions frontend/src/components/common/Dialog.vue

This file was deleted.

18 changes: 8 additions & 10 deletions frontend/src/components/common/ToastMessage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ import Toast from 'primevue/toast';
import { useToast } from 'primevue/usetoast';
import { IconSize } from '@/enum/IconEnum';
import {
useNotificationMessage,
useErrorDialog,
} from '@/store/NotificationState';
const toast = useToast();
const showToastTopRight = (sev: any, title: string, text: string) => {
Expand Down Expand Up @@ -55,13 +50,16 @@ const onError = (error: any, info: string) => {
showToastTopRight(
'error',
e403_authorizationErrorMsg.title,
e403_authorizationErrorMsg.text
axiosResponse?.data.detail.code === 'self_grant_prohibited'
? axiosResponse?.data.detail.description
: e403_authorizationErrorMsg.text
);
} else if (status == 409) {
useNotificationMessage.isNotificationVisible = false;
useErrorDialog.dialogTitle = axiosResponse.statusText;
useErrorDialog.dialogMsg = axiosResponse.data.detail;
useErrorDialog.isErrorVisible = true;
showToastTopRight(
'error',
genericErrorMsg.title,
axiosResponse?.data.detail
);
}
return;
}
Expand Down
14 changes: 9 additions & 5 deletions frontend/src/components/dashboard/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ onMounted(async () => {
await applicationsApi.getApplications()
).data;
if (isApplicationSelected) {
getAppUserRoleAssignment();
await getAppUserRoleAssignment();
}
} catch (error: any) {
return Promise.reject(error);
Expand Down Expand Up @@ -81,10 +81,14 @@ async function getAppUserRoleAssignment() {
}
}
const selectApplication = (e: DropdownChangeEvent) => {
setSelectedApplication(e.value ? JSON.stringify(e.value) : null);
if (isApplicationSelected) {
getAppUserRoleAssignment();
const selectApplication = async (e: DropdownChangeEvent) => {
try {
setSelectedApplication(e.value ? JSON.stringify(e.value) : null);
if (applicationsUserAdministers) {
await getAppUserRoleAssignment();
}
} catch (error: any) {
return Promise.reject(error);
}
};
Expand Down
1 change: 0 additions & 1 deletion frontend/src/components/grantaccess/GrantAccess.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ onMounted(async () => {
resetForm();
}
} catch (error: unknown) {
router.push('/dashboard');
return Promise.reject(error);
}
});
Expand Down
18 changes: 3 additions & 15 deletions frontend/src/components/grantaccess/Summary.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
<script setup lang="ts">
import { onMounted, ref } from 'vue';
import router from '@/router';
import Dialog from '../common/Dialog.vue';
import SummaryCard from './SummaryCard.vue';
import { selectedApplicationDisplayText } from '@/store/ApplicationState';
import {
useNotificationMessage,
useErrorDialog,
} from '@/store/NotificationState';
import { useNotificationMessage } from '@/store/NotificationState';
import {
grantAccessFormData,
Expand All @@ -34,26 +30,18 @@ async function handleSubmit() {
await userRoleAssignmentApi.createUserRoleAssignment(
grantAccessFormData.value as FamUserRoleAssignmentCreate
);
useErrorDialog.isErrorVisible = false;
useNotificationMessage.isNotificationVisible = true;
router.push('/dashboard');
resetGrantAccessFormData();
} catch (err: any) {
return Promise.reject(err);
} finally {
router.push('/dashboard');
resetGrantAccessFormData();
loading.value = false;
}
}
</script>

<template>
<Dialog
v-model:visible="useErrorDialog.isErrorVisible"
:error="true"
:header="useErrorDialog.dialogTitle"
:text-first="useErrorDialog.dialogMsg"
text-second="Contact your administrator for more information."
></Dialog>
<PageTitle
title="Access request summary"
:subtitle="'You are editing in ' + selectedApplicationDisplayText"
Expand Down
12 changes: 8 additions & 4 deletions frontend/src/services/http/HttpResponseInterceptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@ async function authenticationErrorResponsesItcpt(error: any) {
// Special handling; until MAX_RETRY reached.
if (error.response?.status == 401) {
if (retryCount.value < MAX_RETRY) {
return refreshTokenAndReTry(error.config, error.response);
try {
return await refreshTokenAndReTry(error.config, error.response);
} catch (error) {
return Promise.reject(error);
}
} else {
AuthService.methods.removeFamUser(); // Done retry refresh token, token expired; remove user.
router.replace('/'); // 401 unauthenticated/expired, back to home page.
}
AuthService.methods.removeFamUser(); // Done retry refresh token, token expired; remove user.
router.push('/'); // 401 unauthenticated/expired, back to home page.
}

retryCount.value = 0; // Reset counter when retry ends or not 401.
return Promise.reject(error); // return error for next interceptor.
}
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/store/GrantAccessDataState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { FamUserRoleAssignmentCreate } from 'fam-api';
export const domainOptions = { IDIR: 'I', BCEID: 'B' }; // TODO, load it from backend when backend has the endpoint.

export const grantAccessFormData = ref<FamUserRoleAssignmentCreate | null>();
export const grantAccessFormRoleName = ref<String>();
export const grantAccessFormRoleName = ref<string | null>();

export const FOREST_CLIENT_INPUT_MAX_LENGTH = 8;

Expand Down Expand Up @@ -36,5 +36,6 @@ export const getGrantAccessFormData = () => {
}

export const resetGrantAccessFormData = () => {
grantAccessFormRoleName.value = null;
grantAccessFormData.value = null;
}
6 changes: 0 additions & 6 deletions frontend/src/store/NotificationState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,4 @@ import { reactive } from "vue"
export const useNotificationMessage = reactive({
notificationMsg: '',
isNotificationVisible: false,
})

export const useErrorDialog = reactive({
dialogTitle: '',
dialogMsg: '',
isErrorVisible: false,
})

0 comments on commit 5d2a709

Please sign in to comment.