API & Client - update API error messages to remove i18n workarounds

This commit is contained in:
Sam
2021-11-01 09:44:10 +01:00
parent fb6491638c
commit 7f6f33a6aa
36 changed files with 357 additions and 340 deletions

View File

@ -356,7 +356,12 @@
} else {
if (withGpx.value) {
if (!gpxFile) {
throw new Error('No file provided !!')
const errorMessage = 'workouts.NO_FILE_PROVIDED'
store.commit(
ROOT_STORE.MUTATIONS.SET_ERROR_MESSAGES,
errorMessage
)
return
}
payload.file = gpxFile
store.dispatch(WORKOUTS_STORE.ACTIONS.ADD_WORKOUT, payload)

View File

@ -1,21 +1,30 @@
{
"ERROR": {
"UNKNOWN": "Error. Please try again or contact the administrator.",
"Error, Please try again or contact the administrator": "Error. Please try again or contact the administrator.",
"File extension not allowed": "File extension not allowed.",
"File size is greater than the allowed size": "File size is greater than the allowed size.",
"Invalid credentials": "Invalid credentials.",
"Invalid payload": "Invalid data.",
"Invalid token, Please log in again": "Invalid token. Please log in again.",
"email: valid email must be provided": "Email: valid email must be provided.",
"error on getting configuration": "Error on getting configuration.",
"error when updating configuration": "Error when updating configuration",
"error, please try again or contact the administrator": "Error, please try again or contact the administrator.",
"error, registration is disabled": "Error, registration is disabled.",
"file extension not allowed": "File extension not allowed.",
"file size is greater than the allowed size": "File size is greater than the allowed size.",
"invalid credentials": "Invalid credentials.",
"invalid payload": "Provided data are invalid.",
"invalid token, please log in again": "Invalid token, please log in again.",
"invalid token, please request a new token": "Invalid token, please log in again.",
"Network Error": "Network Error.",
"No file part": "No file provided.",
"No selected file": "No selected file.",
"Provide a valid auth token": "Provide a valid auth token.",
"Password and password confirmation don't match": "Password and password confirmation don't match.",
"Password: 8 characters required": "Password: 8 characters required.",
"Signature expired, Please log in again": "Signature expired. Please log in again.",
"Username: 3 to 12 characters required": "Username: 3 to 12 characters required.",
"Valid email must be provided": "Valid email must be provided."
"no file part": "No file provided.",
"no selected file": "No selected file.",
"password: password and password confirmation do not match": "Password: password and password confirmation don't match.",
"provide a valid auth token": "Provide a valid auth token.",
"password: 8 characters required": "Password: 8 characters required.",
"sorry, that user already exists": "Sorry, that user already exists.",
"sport does not exist": "Sport does not exist.",
"signature expired, please log in again": "Signature expired. Please log in again.",
"successfully registered": "Successfully registered.",
"user does not exist": "User does not exist.",
"username: 3 to 12 characters required": "Username: 3 to 12 characters required.",
"you do not have permissions": "You do not have permissions."
},
"PAGINATION": {
"PREVIOUS": "previous",

View File

@ -27,6 +27,7 @@
"NEXT_SEGMENT": "No next segment",
"NEXT_WORKOUT": "Next workout",
"NO_DATA_CLEANING": "data from gpx, without any cleaning",
"NO_FILE_PROVIDED": "No file provided",
"NO_FOLDER": "no folder inside",
"NO_MAP": "No map",
"NO_NEXT_SEGMENT": "No next segment",

View File

@ -1,21 +1,30 @@
{
"ERROR": {
"UNKNOWN": "Erreur. Veuillez réessayer ou contacter l'administrateur.",
"Error, Please try again or contact the administrator": "Erreur. Veuillez réessayer ou contacter l'administrateur.",
"File extension not allowed": "Extension de fichier non autorisée.",
"File size is greater than the allowed size": "La taille du fichier est supérieure à la limite autorisée.",
"Invalid credentials": "Identifiants invalides.",
"Invalid payload": "Données incorrectes.",
"Invalid token, Please log in again": "Jeton invalide. Merci de vous reconnecter.",
"No file part": "Pas de fichier fourni.",
"No selected file": "Pas de fichier sélectionné.",
"email: valid email must be provided": "Email : une adresse email valide doit être fournie.",
"error on getting configuration": "Erreur lors de la récupération de la configuration.",
"error when updating configuration": "Erreur lors de la mise à jour de la configuration",
"error, please try again or contact the administrator": "Erreur, veuillez réessayer ou contacter l'administrateur.",
"error, registration is disabled": "Erreur, les inscriptions sont désactivées.",
"file extension not allowed": "Extension de fichier non autorisée.",
"file size is greater than the allowed size": "La taille du fichier est supérieure à la limite autorisée.",
"invalid credentials": "Identifiants invalides.",
"invalid payload": "Données fournies incorrectes.",
"invalid token, please log in again": "Jeton de connexion invalide, merci de vous reconnecter.",
"invalid token, please request a new token": "Jeton de connexion, merci de vous reconnecter.",
"no file part": "Pas de fichier fourni.",
"no selected file": "Pas de fichier sélectionné.",
"Network Error": "Erreur Réseau.",
"Provide a valid auth token": "Merci de fournir un jeton valide.",
"Password and password confirmation don't match": "Les mots de passe saisis sont différents.",
"Password: 8 characters required": "8 caractères minimum pour le mot de passe.",
"Signature expired, Please log in again": "Signature expirée. Merci de vous reconnecter.",
"Username: 3 to 12 characters required": "3 à 12 caractères requis pour le nom.",
"Valid email must be provided": "L'email fourni n'est pas valide."
"password: password and password confirmation do not match": "Mot de passe : les mots de passe saisis sont différents.",
"provide a valid auth token": "Merci de fournir un jeton de connexion valide.",
"password: 8 characters required": "Mot de passe : 8 caractères minimum.",
"sport does not exist": "Ce sport n'existe pas.",
"signature expired, please log in again": "Signature expirée. Merci de vous reconnecter.",
"sorry, that user already exists": "Désolé, cet utilisateur existe déjà.",
"successfully registered": "Inscription validée.",
"user does not exist": "L'utilisateur n'existe pas",
"username: 3 to 12 characters required": "Nom d'utilisateur : 3 à 12 caractères requis.",
"you do not have permissions": "Vous n'avez pas les permissions nécessaires."
},
"PAGINATION": {
"PREVIOUS": "précédent",

View File

@ -27,6 +27,7 @@
"NEXT_SEGMENT": "Segment suivant",
"NEXT_WORKOUT": "Séance suivante",
"NO_DATA_CLEANING": "données issues du fichier gpx, sans correction",
"NO_FILE_PROVIDED": "Pas de fichier fourni",
"NO_FOLDER": "pas de répertoire",
"NO_MAP": "Pas de carte",
"NO_NEXT_SEGMENT": "Pas de segment suivant",

View File

@ -15,11 +15,6 @@ export const getApiUrl = (): string => {
: `${process.env.VUE_APP_API_URL}/api/`
}
// TODO: update api error messages to remove these workarounds
const removeLastEndOfLine = (text: string): string => text.replace(/\n$/gm, '')
const removeLastDot = (text: string): string => text.replace(/\.$/gm, '')
const replaceInternalDots = (text: string): string => text.replace(/\./gm, ',')
export const handleError = (
context:
| ActionContext<IRootState, IRootState>
@ -31,25 +26,24 @@ export const handleError = (
error: AxiosError | null,
msg = 'UNKNOWN'
): void => {
let errorMessages = !error
const errorMessages = !error
? msg
: error.response
? error.response.status === 413
? 'File size is greater than the allowed size'
? 'file size is greater than the allowed size'
: error.response.data.message
? error.response.data.message
: msg
: error.message
? error.message
: msg
errorMessages = removeLastEndOfLine(errorMessages)
errorMessages = replaceInternalDots(errorMessages)
context.commit(
ROOT_STORE.MUTATIONS.SET_ERROR_MESSAGES,
errorMessages.includes('\n')
? errorMessages
.split('\n')
.map((m: string) => `api.ERROR.${removeLastDot(m)}`)
: `api.ERROR.${removeLastDot(errorMessages)}`
.filter((m: string) => m !== '')
.map((m: string) => `api.ERROR.${m}`)
: `api.ERROR.${errorMessages}`
)
}