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: simplified error messages for invalid inputs at profile settings #2500

Open
wants to merge 20 commits into
base: develop-postgres
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 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
8 changes: 7 additions & 1 deletion public/locales/en/errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@
"emailNotRegistered": "Email not registered",
"notFoundMsg": "Oops! The Page you requested was not found!",
"errorOccurredCouldntCreate": "An error occurred. Couldn't create {{entity}}",
"errorLoading": "Error occured while loading {{entity}} data"
"errorLoading": "Error occured while loading {{entity}} data",
"invalidPhoneNumber": "Please enter a valid phone number",
"invalidEducationGrade": "Please select a valid education grade",
"invalidEmploymentStatus": "Please select a valid employment status",
"invalidMaritalStatus": "Please select a valid marital status",
"error400": "The submitted information is invalid. Please check your inputs and try again",
"defaultError": "Something went wrong. Please try again later"
bandhan-majumder marked this conversation as resolved.
Show resolved Hide resolved
}
8 changes: 7 additions & 1 deletion public/locales/fr/errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@
"emailNotRegistered": "Email non enregistré",
"notFoundMsg": "Oops! ",
"errorOccurredCouldntCreate": "Une erreur s'est produite. Impossible de créer {{entity}}",
"errorLoading": "Une erreur s'est produite lors du chargement des données {{entity}}"
"errorLoading": "Une erreur s'est produite lors du chargement des données {{entity}}",
"invalidPhoneNumber": "Veuillez entrer un numéro de téléphone valide",
"invalidEducationGrade": "Veuillez sélectionner un niveau d'études valide",
"invalidEmploymentStatus": "Veuillez sélectionner un statut d'emploi valide",
"invalidMaritalStatus": "Veuillez sélectionner un état matrimonial valide",
"error400": "La requête n'a pas pu être traitée. Veuillez vérifier vos informations",
"defaultError": "Une erreur s'est produite. Veuillez réessayer ultérieurement"
}
8 changes: 7 additions & 1 deletion public/locales/hi/errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@
"emailNotRegistered": "ईमेल पंजीकृत नहीं है",
"notFoundMsg": "उफ़! ",
"errorOccurredCouldntCreate": "एक त्रुटि हुई। {{entity}} नहीं बना सके",
"errorLoading": "{{entity}} डेटा लोड करते समय त्रुटि हुई"
"errorLoading": "{{entity}} डेटा लोड करते समय त्रुटि हुई",
"invalidPhoneNumber": "कृपया एक मान्य फोन-नंबर दर्ज करे",
"invalidEducationGrade": "कृपया एक शिक्षा ग्रेड चुनें",
"invalidEmploymentStatus": "कृपया वैध रोजगार स्थिति चुनें",
"invalidMaritalStatus": "कृपया वैध वैवाहिक स्थिति चुनें",
"error400": "आपकी जानकारी सहेजी नहीं जा सकी। कृपया अपनी प्रविष्टियों की जांच करें और पुनः प्रयास करें।",
"defaultError": "कुछ गलत हो गया है। कृपया बाद में दोबारा प्रयास करें।"
}
8 changes: 7 additions & 1 deletion public/locales/sp/errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@
"emailNotRegistered": "Email not registered",
"notFoundMsg": "Oops! The Page you requested was not found!",
"errorOccurredCouldntCreate": "Ocurrió un error. No se pudo crear {{entity}}",
"errorLoading": "Ocurrió un error al cargar los datos de {{entity}}"
"errorLoading": "Ocurrió un error al cargar los datos de {{entity}}",
"invalidPhoneNumber": "Por favor, introduzca un número de teléfono válido",
"invalidEducationGrade": "Por favor seleccione un grado de educación válido",
"invalidEmploymentStatus": "Por favor seleccione un estado de empleo válido",
"invalidMaritalStatus": "Por favor seleccione un estado civil válido",
"error400": "No se pudo procesar su solicitud. Por favor, verifique la información ingresada",
"defaultError": "Algo salió mal. Inténtalo de nuevo más tarde."
}
8 changes: 7 additions & 1 deletion public/locales/zh/errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@
"emailNotRegistered": "邮箱未注册",
"notFoundMsg": "哎呀!",
"errorOccurredCouldntCreate": "发生错误。 无法创建{{entity}}",
"errorLoading": "加载{{entity}}数据时出错"
"errorLoading": "加载{{entity}}数据时出错",
"invalidPhoneNumber": "请选择一个有效的电话号码",
"invalidEducationGrade": "请选择教育年级",
"invalidEmploymentStatus": "请选择有效的就业状况",
"invalidMaritalStatus": "请选择有效的婚姻状况",
"error400": "无法处理您的请求,请检查输入是否正确",
"defaultError": "出了点问题。请稍后重试。"
}
22 changes: 15 additions & 7 deletions src/utils/errorHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,21 @@ import i18n from './i18n';
export const errorHandler = (a: unknown, error: unknown): void => {
const tErrors: TFunction = i18n.getFixedT(null, 'errors');
if (error instanceof Error) {
switch (error.message) {
case 'Failed to fetch':
toast.error(tErrors('talawaApiUnavailable') as string);
break;
// Add more cases as needed
default:
toast.error(error.message);
const errorMessage = error.message;
if (errorMessage === 'Failed to fetch') {
toast.error(tErrors('talawaApiUnavailable'));
} else if (errorMessage.includes('Value is not a valid phone number')) {
toast.error(tErrors('invalidPhoneNumber'));
} else if (errorMessage.includes('does not exist in "EducationGrade"')) {
toast.error(tErrors('invalidEducationGrade'));
} else if (errorMessage.includes('does not exist in "EmploymentStatus"')) {
toast.error(tErrors('invalidEmploymentStatus'));
} else if (errorMessage.includes('does not exist in "MaritalStatus"')) {
toast.error(tErrors('invalidMaritalStatus'));
} else if (errorMessage.includes('status code 400')) {
toast.error(tErrors('error400'));
bandhan-majumder marked this conversation as resolved.
Show resolved Hide resolved
} else {
toast.error(tErrors('defaultError'));
}
} else {
toast.error(tErrors('unknownError', { msg: error }) as string);
Expand Down