Account for 409 response codes
This commit is contained in:
parent
4f081abb7a
commit
5b61aa39a7
2 changed files with 21 additions and 6 deletions
|
@ -1,3 +1,4 @@
|
|||
import { AxiosError } from 'axios';
|
||||
import React, { useEffect } from 'react';
|
||||
import { FormattedMessage, defineMessages, useIntl } from 'react-intl';
|
||||
|
||||
|
@ -17,7 +18,8 @@ type RouteParams = { groupId: string };
|
|||
|
||||
const messages = defineMessages({
|
||||
heading: { id: 'column.group_pending_requests', defaultMessage: 'Pending requests' },
|
||||
authorizeRejectFail: { id: 'group.membership_requests.fail', defaultMessage: 'Group owner or admin has already taken action on this request.' },
|
||||
authorizeFail: { id: 'group.group_mod_authorize.fail', defaultMessage: 'Failed to approve @{name}' },
|
||||
rejectFail: { id: 'group.group_mod_reject.fail', defaultMessage: 'Failed to reject @{name}' },
|
||||
});
|
||||
|
||||
interface IMembershipRequest {
|
||||
|
@ -81,9 +83,15 @@ const GroupMembershipRequests: React.FC<IGroupMembershipRequests> = ({ params })
|
|||
async function handleAuthorize(account: AccountEntity) {
|
||||
return authorize(account.id)
|
||||
.then(() => Promise.resolve())
|
||||
.catch(() => {
|
||||
.catch((error: AxiosError) => {
|
||||
refetch();
|
||||
toast.error(intl.formatMessage(messages.authorizeRejectFail));
|
||||
|
||||
let message = intl.formatMessage(messages.authorizeFail, { name: account.username });
|
||||
if (error.response?.status === 409) {
|
||||
message = (error.response?.data as any).error;
|
||||
}
|
||||
toast.error(message);
|
||||
|
||||
return Promise.reject();
|
||||
});
|
||||
}
|
||||
|
@ -91,9 +99,15 @@ const GroupMembershipRequests: React.FC<IGroupMembershipRequests> = ({ params })
|
|||
async function handleReject(account: AccountEntity) {
|
||||
return reject(account.id)
|
||||
.then(() => Promise.resolve())
|
||||
.catch(() => {
|
||||
.catch((error: AxiosError) => {
|
||||
refetch();
|
||||
toast.error(intl.formatMessage(messages.authorizeRejectFail));
|
||||
|
||||
let message = intl.formatMessage(messages.rejectFail, { name: account.username });
|
||||
if (error.response?.status === 409) {
|
||||
message = (error.response?.data as any).error;
|
||||
}
|
||||
toast.error(message);
|
||||
|
||||
return Promise.reject();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -773,12 +773,14 @@
|
|||
"group.delete.success": "Group successfully deleted",
|
||||
"group.deleted.message": "This group has been deleted.",
|
||||
"group.demote.user.success": "@{name} is now a member",
|
||||
"group.group_mod_authorize.fail": "Failed to approve @{name}",
|
||||
"group.group_mod_block": "Ban from group",
|
||||
"group.group_mod_block.success": "@{name} is banned",
|
||||
"group.group_mod_demote": "Remove {role} role",
|
||||
"group.group_mod_kick": "Kick @{name} from group",
|
||||
"group.group_mod_kick.success": "Kicked @{name} from group",
|
||||
"group.group_mod_promote_mod": "Assign {role} role",
|
||||
"group.group_mod_reject.fail": "Failed to reject @{name}",
|
||||
"group.group_mod_unblock": "Unban",
|
||||
"group.group_mod_unblock.success": "Unbanned @{name} from group",
|
||||
"group.header.alt": "Group header",
|
||||
|
@ -792,7 +794,6 @@
|
|||
"group.manage": "Manage Group",
|
||||
"group.member.admin.limit.summary": "You can assign up to {count} admins for the group at this time.",
|
||||
"group.member.admin.limit.title": "Admin limit reached",
|
||||
"group.membership_requests.fail": "Group owner or admin has already taken action on this request.",
|
||||
"group.popover.action": "View Group",
|
||||
"group.popover.summary": "You must be a member of the group in order to reply to this status.",
|
||||
"group.popover.title": "Membership required",
|
||||
|
|
Loading…
Reference in a new issue