Skip to content

Commit

Permalink
fix axios bug not returning error mesages
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavomm19 committed Feb 21, 2025
1 parent a679af7 commit 653b984
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
3 changes: 2 additions & 1 deletion public/locales/en/login.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"not-you": "Not you?",
"email-not-found": "We could not find an account with this email",
"email-not-validated": "You need to validate your email first,",
"validation-link": "resend validation link",
"validation-link": "resend validation email",
"invitation-message": "The validation email has been sent to your email, please follow the instructions in the email. If you can't find it, check the spam folder",
"invitation-sended": "The invitation was resended! Check your inbox",
"invitation-error": "Something went wrong sending the invitation",
"login": "Log in",
Expand Down
3 changes: 2 additions & 1 deletion public/locales/es/login.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"not-you": "¿No eres tu?",
"email-not-found": "No pudimos encontrar una cuenta con este email",
"email-not-validated": "Debes validar tu email primero,",
"validation-link": "reenviar link de invitación",
"validation-link": "reenviar email de invitación",
"invitation-message": "El email de validación se ha enviado a su correo electrónico, siga las instrucciones que se indican en el email. Si no lo encuentra, revise la carpeta de correo no deseado.",
"invitation-sended": "¡La invitación fue reenviada! Revisa tu bandeja de entrada",
"invitation-error": "Hubo un error enviando la invitación",
"login": "Ingresar",
Expand Down
11 changes: 11 additions & 0 deletions src/axios.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ axiosInstance.interceptors.request.use((config) => {
};
});

axiosInstance.interceptors.response.use(
(response) => response, // Return the response as is for successful requests
(error) => {
if (error.response) {
// If the server responded with a status code outside 2xx
return error.response; // Reject with error response instead of the whole error object
}
return error; // Handle cases where no response was received
},
);

// Function to manually cancel the request in progress
export const cancelAllCurrentRequests = (message = 'All request was canceled') => {
try {
Expand Down
18 changes: 16 additions & 2 deletions src/common/components/Forms/LogIn.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,24 @@ function LogIn({ hideLabel, actionfontSize, callBack, disableRedirect }) {
isClosable: true,
});
} else {
const { data } = resp;
toast({
position: 'top',
title: t('invitation-error'),
title: data.detail,
status: 'error',
duration: 9000,
isClosable: true,
});
}
} catch (e) {
console.log(e);
toast({
position: 'top',
title: t('invitation-error'),
status: 'error',
duration: 9000,
isClosable: true,
});
}
};

Expand Down Expand Up @@ -233,10 +241,16 @@ function LogIn({ hideLabel, actionfontSize, callBack, disableRedirect }) {
)}
</Text>
)}
{!invitationSent && (
{!invitationSent ? (
<Button onClick={() => validateEmail(values.email)} isLoading={emailValidation.loading} isDisabled={errors.email} variant="default" fontSize={actionfontSize || 'l'} type="button">
{t('next')}
</Button>
) : (
<Box padding="5px" borderRadius="5px" background={hexColor.featuredColor}>
<Text size="md" marginLeft="10px">
{t('invitation-message')}
</Text>
</Box>
)}
</>
)}
Expand Down

0 comments on commit 653b984

Please sign in to comment.