diff --git a/test/api/v3/integration/groups/POST-groups_invite.test.js b/test/api/v3/integration/groups/POST-groups_invite.test.js index 385fa431a6..712c9a8f3c 100644 --- a/test/api/v3/integration/groups/POST-groups_invite.test.js +++ b/test/api/v3/integration/groups/POST-groups_invite.test.js @@ -322,18 +322,18 @@ describe('Post /groups/:groupId/invite', () => { describe('guild invites', () => { it('returns an error when invited user is already invited to the group', async () => { - let userToInivite = await generateUser(); + let userToInvite = await generateUser(); await inviter.post(`/groups/${group._id}/invite`, { - uuids: [userToInivite._id], + uuids: [userToInvite._id], }); await expect(inviter.post(`/groups/${group._id}/invite`, { - uuids: [userToInivite._id], + uuids: [userToInvite._id], })) .to.eventually.be.rejected.and.eql({ code: 401, error: 'NotAuthorized', - message: t('userAlreadyInvitedToGroup'), + message: t('userAlreadyInvitedToGroup', { userId: userToInvite._id, username: userToInvite.profile.name}), }); }); @@ -350,7 +350,7 @@ describe('Post /groups/:groupId/invite', () => { .to.eventually.be.rejected.and.eql({ code: 401, error: 'NotAuthorized', - message: t('userAlreadyInGroup'), + message: t('userAlreadyInGroup', { userId: userToInvite._id, username: userToInvite.profile.name}), }); }); @@ -410,7 +410,7 @@ describe('Post /groups/:groupId/invite', () => { .to.eventually.be.rejected.and.eql({ code: 401, error: 'NotAuthorized', - message: t('userAlreadyPendingInvitation'), + message: t('userAlreadyPendingInvitation', { userId: userToInvite._id, username: userToInvite.profile.name}), }); }); @@ -429,7 +429,7 @@ describe('Post /groups/:groupId/invite', () => { .to.eventually.be.rejected.and.eql({ code: 401, error: 'NotAuthorized', - message: t('userAlreadyInAParty'), + message: t('userAlreadyInAParty', { userId: userToInvite._id, username: userToInvite.profile.name}), }); }); diff --git a/website/client/app.vue b/website/client/app.vue index 18f1adbe50..c1c877dfa0 100644 --- a/website/client/app.vue +++ b/website/client/app.vue @@ -229,9 +229,12 @@ export default { return Promise.resolve(error); } + const errorData = error.response.data; + const errorMessage = errorData.message || errorData; + this.$store.dispatch('snackbars:add', { title: 'Habitica', - text: error.response.data, + text: errorMessage, type: 'error', timeout: true, }); diff --git a/website/common/locales/en/groups.json b/website/common/locales/en/groups.json index e98f66076a..9029b2715a 100644 --- a/website/common/locales/en/groups.json +++ b/website/common/locales/en/groups.json @@ -222,11 +222,11 @@ "inviteMissingUuid": "Missing user id in invite", "inviteMustNotBeEmpty": "Invite must not be empty.", "partyMustbePrivate": "Parties must be private", - "userAlreadyInGroup": "User already in that group.", + "userAlreadyInGroup": "UserID: <%= userId %>, User \"<%= username %>\" already in that group.", "cannotInviteSelfToGroup": "You cannot invite yourself to a group.", - "userAlreadyInvitedToGroup": "User already invited to that group.", - "userAlreadyPendingInvitation": "User already pending invitation.", - "userAlreadyInAParty": "User already in a Party.", + "userAlreadyInvitedToGroup": "UserID: <%= userId %>, User \"<%= username %>\" already invited to that group.", + "userAlreadyPendingInvitation": "UserID: <%= userId %>, User \"<%= username %>\" already pending invitation.", + "userAlreadyInAParty": "UserID: <%= userId %>, User \"<%= username %>\" already in a party. ", "userWithIDNotFound": "User with id \"<%= userId %>\" not found.", "userHasNoLocalRegistration": "User does not have a local registration (username, email, password).", "uuidsMustBeAnArray": "User ID invites must be an array.", diff --git a/website/server/controllers/api-v3/groups.js b/website/server/controllers/api-v3/groups.js index bcc321d427..67512a51bb 100644 --- a/website/server/controllers/api-v3/groups.js +++ b/website/server/controllers/api-v3/groups.js @@ -935,10 +935,10 @@ async function _inviteByUUID (uuid, group, inviter, req, res) { if (group.type === 'guild') { if (_.includes(userToInvite.guilds, group._id)) { - throw new NotAuthorized(res.t('userAlreadyInGroup')); + throw new NotAuthorized(res.t('userAlreadyInGroup', { userId: uuid, username: userToInvite.profile.name})); } if (_.find(userToInvite.invitations.guilds, {id: group._id})) { - throw new NotAuthorized(res.t('userAlreadyInvitedToGroup')); + throw new NotAuthorized(res.t('userAlreadyInvitedToGroup', { userId: uuid, username: userToInvite.profile.name})); } let guildInvite = { @@ -952,14 +952,14 @@ async function _inviteByUUID (uuid, group, inviter, req, res) { } else if (group.type === 'party') { // Do not add to invitations.parties array if the user is already invited to that party if (_.find(userToInvite.invitations.parties, {id: group._id})) { - throw new NotAuthorized(res.t('userAlreadyPendingInvitation')); + throw new NotAuthorized(res.t('userAlreadyPendingInvitation', { userId: uuid, username: userToInvite.profile.name})); } if (userToInvite.party._id) { let userParty = await Group.getGroup({user: userToInvite, groupId: 'party', fields: 'memberCount'}); // Allow user to be invited to a new party when they're partying solo - if (userParty && userParty.memberCount !== 1) throw new NotAuthorized(res.t('userAlreadyInAParty')); + if (userParty && userParty.memberCount !== 1) throw new NotAuthorized(res.t('userAlreadyInAParty', { userId: uuid, username: userToInvite.profile.name})); } let partyInvite = {id: group._id, name: group.name, inviter: inviter._id};