fix: Show error messages from response (#10173)

This PR fixes the issue where proper error messages from the backend
were not displayed when an email already exists in the system during a
profile update, or when a phone number is already taken for Twilio
during the creation of a new account.

Fixes:
https://linear.app/chatwoot/issue/CW-3560/prod-customer-facing-issue-updating-email
This commit is contained in:
Sivin Varghese
2024-09-27 08:46:39 +05:30
committed by GitHub
parent 4a7a0427e9
commit f4f2d678cf
3 changed files with 8 additions and 5 deletions

View File

@@ -6,6 +6,7 @@ import { useAlert } from 'dashboard/composables';
import { required } from '@vuelidate/validators'; import { required } from '@vuelidate/validators';
import router from '../../../../index'; import router from '../../../../index';
import { isPhoneE164OrEmpty } from 'shared/helpers/Validators'; import { isPhoneE164OrEmpty } from 'shared/helpers/Validators';
import { parseAPIErrorResponse } from 'dashboard/store/utils/api';
export default { export default {
props: { props: {
@@ -101,7 +102,10 @@ export default {
}, },
}); });
} catch (error) { } catch (error) {
useAlert(this.$t('INBOX_MGMT.ADD.TWILIO.API.ERROR_MESSAGE')); const errorMessage =
parseAPIErrorResponse(error) ||
this.$t('INBOX_MGMT.ADD.TWILIO.API.ERROR_MESSAGE');
useAlert(errorMessage);
} }
}, },
}, },

View File

@@ -4,6 +4,7 @@ import { useAlert } from 'dashboard/composables';
import { useUISettings } from 'dashboard/composables/useUISettings'; import { useUISettings } from 'dashboard/composables/useUISettings';
import { clearCookiesOnLogout } from 'dashboard/store/utils/api.js'; import { clearCookiesOnLogout } from 'dashboard/store/utils/api.js';
import { copyTextToClipboard } from 'shared/helpers/clipboard'; import { copyTextToClipboard } from 'shared/helpers/clipboard';
import { parseAPIErrorResponse } from 'dashboard/store/utils/api';
import globalConfigMixin from 'shared/mixins/globalConfigMixin'; import globalConfigMixin from 'shared/mixins/globalConfigMixin';
import UserProfilePicture from './UserProfilePicture.vue'; import UserProfilePicture from './UserProfilePicture.vue';
import UserBasicDetails from './UserBasicDetails.vue'; import UserBasicDetails from './UserBasicDetails.vue';
@@ -109,9 +110,7 @@ export default {
return true; // return the value so that the status can be known return true; // return the value so that the status can be known
} catch (error) { } catch (error) {
alertMessage = error?.response?.data?.error alertMessage = parseAPIErrorResponse(error) || errorMessage;
? error.response.data.error
: errorMessage;
return false; // return the value so that the status can be known return false; // return the value so that the status can be known
} finally { } finally {

View File

@@ -183,7 +183,7 @@ export const actions = {
return response.data; return response.data;
} catch (error) { } catch (error) {
commit(types.default.SET_INBOXES_UI_FLAG, { isCreating: false }); commit(types.default.SET_INBOXES_UI_FLAG, { isCreating: false });
throw new Error(error); throw error;
} }
}, },
createFBChannel: async ({ commit }, params) => { createFBChannel: async ({ commit }, params) => {