Skip to content

Commit

Permalink
fix: Dépile les requetes en erreur 400
Browse files Browse the repository at this point in the history
  • Loading branch information
GregoireDucharme committed Jan 7, 2025
1 parent 95a7aa9 commit 7dee7b2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 11 deletions.
20 changes: 10 additions & 10 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,17 @@ router.afterEach(async () => {
try {
await storage.sync();
} catch (error) {
if (
error.name === "AxiosError" &&
[AxiosError.ETIMEDOUT, AxiosError.ECONNABORTED, AxiosError.ERR_NETWORK].includes(error.code)
) {
toast.error(
"Une erreur de réseau est survenue. Si votre connexion " +
"est instable, vous pouvez passer en mode hors-ligne.",
);
return;
if (error.name === "AxiosError") {
if ([AxiosError.ETIMEDOUT, AxiosError.ECONNABORTED, AxiosError.ERR_NETWORK].includes(error.code)) {
toast.error(
"Une erreur de réseau est survenue. Si votre connexion " +
"est instable, vous pouvez passer en mode hors-ligne.",
);
return;
} else if (error.code === AxiosError.ERR_BAD_REQUEST) {
toast.error("Un problème technique est survenu. Veuillez réessayer ultérieurement.");
}
}

throw error;
}
});
Expand Down
29 changes: 28 additions & 1 deletion src/stores/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { computed, ref, watch } from "vue";
import { useLocalStorage, useOnline } from "@vueuse/core";
import { apiClient, createOperatorRecord } from "@/cartobio-api.js";
import { legalProjectionSurface } from "@/utils/features.js";
import { AxiosError } from "axios";
import toast from "@/utils/toast.js";

/**
* @typedef {import('@agencebio/cartobio-types').AgenceBioNormalizedOperator} AgenceBioNormalizedOperator
Expand Down Expand Up @@ -454,6 +456,10 @@ export const useCartoBioStorage = defineStore("storage", () => {
continue;
}

if (e.response?.status === 400) {
delete syncQueues.value[recordId];
}

throw e;
}
}
Expand All @@ -462,7 +468,28 @@ export const useCartoBioStorage = defineStore("storage", () => {
}
}

watch(() => [online, syncQueues], sync, { deep: true });
watch(
() => [online, syncQueues],
async () => {
try {
await sync();
} catch (error) {
if (error.name === "AxiosError") {
if ([AxiosError.ETIMEDOUT, AxiosError.ECONNABORTED, AxiosError.ERR_NETWORK].includes(error.code)) {
toast.error(
"Une erreur de réseau est survenue. Si votre connexion " +
"est instable, vous pouvez passer en mode hors-ligne.",
);
return;
} else if (error.code === AxiosError.ERR_BAD_REQUEST) {
toast.error("Un problème technique est survenu. Veuillez réessayer ultérieurement.");
}
}
throw error;
}
},
{ deep: true },
);

return {
// storage ref
Expand Down

0 comments on commit 7dee7b2

Please sign in to comment.