Skip to content

Commit

Permalink
Merge pull request #1521 from betagouv/1504-error-message
Browse files Browse the repository at this point in the history
Changement du message d'erreur en cas de token CSRF pas à jour
  • Loading branch information
alemangui authored Jan 23, 2025
2 parents 41f4d10 + 935ac7c commit e710bc7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
9 changes: 5 additions & 4 deletions frontend/src/utils/error-handling.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ export const handleError = async (response) => {
// Handle display of the errors (directly on the form or in a toast)
// https://vuelidate-next.netlify.app/advanced_usage.html#config-with-composition-api
const backErrorData = await response.value.json()
if (backErrorData.globalError) {
// show an error toast
addErrorMessage(backErrorData.globalError)
}
const isCsrfError = backErrorData.globalError?.indexOf?.("CSRF Failed") > -1

if (isCsrfError) addErrorMessage("Veuillez rafraîchir la page pour mettre à jour votre session.")
else if (backErrorData.globalError) addErrorMessage(backErrorData.globalError)

// Return other errors to be handled by Vuelidate directly (and "extra" parameters to get additional data)
// If you don't have a form and expect global errors only, just ignore the result of this function when called.
return {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/DeclaredElementPage/ElementSynonyms.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</template>

<script setup>
import { ref, computed } from "vue"
import { computed } from "vue"
import { getElementName } from "@/utils/elements"
const props = defineProps({ initialSynonyms: Array, requestElement: Object })
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/NewElementsPage/ElementLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
</template>

<script setup>
const props = defineProps({ element: Object })
defineProps({ element: Object })
</script>
14 changes: 9 additions & 5 deletions frontend/src/views/ProducerFormPage/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,15 @@ const savePayload = async (successMessage = "Votre démarche a été sauvegardé
const { response, data } = await useFetch(url, { headers: headers() })[httpMethod](payload).json()
requestInProgress.value = false
$externalResults.value = await handleError(response)
if ($externalResults.value) {
useToaster().addErrorMessage(
"Merci de vérifier que les champs obligatoires, signalés par une astérix *, ont bien été remplis pour pouvoir changer d'onglet"
)
window.scrollTo(0, 0)
const hasError = !!$externalResults.value
if (hasError) {
const fieldErrors = $externalResults.value.fieldErrors
if (fieldErrors && Object.keys(fieldErrors).length > 0) {
useToaster().addErrorMessage(
"Merci de vérifier que les champs obligatoires, signalés par une astérix *, ont bien été remplis pour pouvoir changer d'onglet"
)
window.scrollTo(0, 0)
}
return false
} else {
payload.value = data.value
Expand Down

0 comments on commit e710bc7

Please sign in to comment.