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

FIX : Ajout gestion erreur si le backend est down. #164

Merged
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
29 changes: 24 additions & 5 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@
</template>

<script setup>
import {computed, ref} from 'vue'
import {computed, ref, watch} from 'vue'
import Header from '@/components/Structure/Header.vue'
import Navbar from '@/components/Structure/Navbar.vue'
import Footer from '@/components/Structure/Footer.vue'
import router from '@/router/index'
import {HttpStatusCode} from 'axios'
import InfoAppBanner from '@/components/Structure/InfoAppBanner.vue'
import {useAuthStore} from '@/store/authStore'
import {useRoute} from "vue-router";


const errorStack = ref([])
const drawer = ref(false)
Expand All @@ -53,29 +55,46 @@ const authenticated = computed(() => {
return authStore.isAuthenticated
})

const route = useRoute();

watch(
() => route.query.error,
(error) => {
if (error) {
let newError = {
message: 'Erreur réseau',
description: 'Service indisponible : merci de réessayer ultérieurement.'
}
errorStack.value.push(newError);
}
},
{ immediate: true } // Option pour exécuter le watcher dès le montage du composant
);


function addError(error) {
let newError = {
message: 'Erreur',
description: ''
}
if(!error.response){
newError.message = 'Erreur réseau : ' + error.code
newError.description = 'Le serveur ne répond pas. Vérifiez sa disponibilité.'
newError.description = 'Service indisponible : merci de réessayer ultérieurement.'
}else{
if (error.response.status === HttpStatusCode.NotFound){
newError.message = 'Impossible de récupérer les données'
newError.description = 'Vérifiez que vos urls d\'appel au serveur sont correctes ainsi que vos clés d\'autorisation ' + '(' + error.config.url + ')'
}
if(error.response.status === HttpStatusCode.Forbidden){
newError.message = 'Accès rejeté par le serveur'
newError.message = 'Accès rejeté'
newError.description = 'Vérifiez que vos urls d\'appel au serveur sont correctes ainsi que vos clés d\'autorisation ' + '(' + error.config.url + ')'
}
if(error.response.status === HttpStatusCode.Unauthorized){
newError.message = 'Accès refusé par le serveur'
newError.message = 'Accès refusé'
newError.description = error.response.data.message + '(' + error.config.url + ')'
}
if(error.response.status === HttpStatusCode.BadRequest){
newError.message = 'Accès rejeté par le serveur'
newError.message = 'Accès rejeté'
newError.description = 'Mauvaise requête : contrôlez les paramètres de votre requête et observez les logs du serveur pour plus d\'informations ' + '(' + error.config.url + ')'
}
if(error.response.status.toString().startsWith('5')){
Expand Down
6 changes: 3 additions & 3 deletions src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,14 @@ router.beforeEach(async (to, from, next) => {
if (valid.data) {
next();
} else {
console.error('Token invalide auprès du serveur');
console.error('Token invalide : vous ne pouvez pas accéder à l\'application');
itemService.logout();
next('/identification');
next({ name: 'identification', query: { error: 'Token invalide : vous ne pouvez pas accéder à l\'application' } });
}
} catch (error) {
console.error(error);
itemService.logout();
next('/identification');
next({ name: 'identification', query: { error: 'Service indisponible : merci de réessayer ultérieurement' } });
}
} else {
next('/identification');
Expand Down
Loading