Skip to content

Commit

Permalink
Merge d5b9fd0 into cf8de83
Browse files Browse the repository at this point in the history
  • Loading branch information
swain committed Dec 27, 2023
2 parents cf8de83 + d5b9fd0 commit 50bfc33
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/components/Invitations/InviteProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,32 @@ export type InviteProviderProps = {
children: React.ReactNode;
};

const isInviteAlreadyAcceptedErrorResponse =
/* istanbul ignore next */
(response: unknown) => {
if (!response) {
return false;
}

if (typeof response !== 'object') {
return;
}

if ('code' in response && response.code === 'INVITATION_ALREADY_ACCEPTED') {
return true;
}

if (
'error' in response &&
typeof response.error === 'string' &&
response.error.includes('already accepted')
) {
return true;
}

return false;
};

export const InviteProvider: React.FC<InviteProviderProps> = ({ children }) => {
const pendingInvite = usePendingInvite();
const { refreshForInviteAccept } = useAuth();
Expand All @@ -45,7 +71,7 @@ export const InviteProvider: React.FC<InviteProviderProps> = ({ children }) => {
// Do not include account header on this request.
axios: { headers: { 'LifeOmic-Account': '' } },
onError: (error: any) => {
if (error?.response?.data?.code === 'INVITATION_ALREADY_ACCEPTED') {
if (isInviteAlreadyAcceptedErrorResponse(error.response?.data)) {
console.warn('Ignoring already accepted invite');
} else {
console.warn('Error accepting invitation', error);
Expand Down

0 comments on commit 50bfc33

Please sign in to comment.