Add exception handling for already joined users
This commit is contained in:
parent
ba900e913f
commit
86e938794b
@ -1,5 +1,6 @@
|
|||||||
import { expect, jest, test } from '@jest/globals'
|
import { expect, jest, test } from '@jest/globals'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
|
import { Entity, entities } from '../Entities'
|
||||||
import { IdMapping } from '../entity/IdMapping'
|
import { IdMapping } from '../entity/IdMapping'
|
||||||
import * as storage from '../helpers/storage'
|
import * as storage from '../helpers/storage'
|
||||||
import { SessionOptions } from '../helpers/synapse'
|
import { SessionOptions } from '../helpers/synapse'
|
||||||
@ -9,15 +10,14 @@ import {
|
|||||||
RcRoom,
|
RcRoom,
|
||||||
RcRoomTypes,
|
RcRoomTypes,
|
||||||
acceptInvitation,
|
acceptInvitation,
|
||||||
|
createDirectChatMemberships,
|
||||||
createMapping,
|
createMapping,
|
||||||
getCreator,
|
getCreator,
|
||||||
getFilteredMembers,
|
getFilteredMembers,
|
||||||
inviteMember,
|
inviteMember,
|
||||||
mapRoom,
|
mapRoom,
|
||||||
createDirectChatMemberships,
|
|
||||||
registerRoom,
|
registerRoom,
|
||||||
} from './rooms'
|
} from './rooms'
|
||||||
import { Entity, entities } from '../Entities'
|
|
||||||
|
|
||||||
jest.mock('axios')
|
jest.mock('axios')
|
||||||
const mockedAxios = axios as jest.Mocked<typeof axios>
|
const mockedAxios = axios as jest.Mocked<typeof axios>
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import { AxiosError } from 'axios'
|
||||||
import { Entity, entities } from '../Entities'
|
import { Entity, entities } from '../Entities'
|
||||||
import { IdMapping } from '../entity/IdMapping'
|
import { IdMapping } from '../entity/IdMapping'
|
||||||
import log from '../helpers/logger'
|
import log from '../helpers/logger'
|
||||||
@ -160,11 +161,26 @@ export async function inviteMember(
|
|||||||
creatorSessionOptions: SessionOptions | object
|
creatorSessionOptions: SessionOptions | object
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
log.http(`Invite member ${inviteeId}`)
|
log.http(`Invite member ${inviteeId}`)
|
||||||
await axios.post(
|
try {
|
||||||
`/_matrix/client/v3/rooms/${roomId}/invite`,
|
await axios.post(
|
||||||
{ user_id: inviteeId },
|
`/_matrix/client/v3/rooms/${roomId}/invite`,
|
||||||
creatorSessionOptions
|
{ user_id: inviteeId },
|
||||||
)
|
creatorSessionOptions
|
||||||
|
)
|
||||||
|
} catch (error) {
|
||||||
|
if (
|
||||||
|
error instanceof AxiosError &&
|
||||||
|
error.response &&
|
||||||
|
error.response.data.errcode === 'M_FORBIDDEN' &&
|
||||||
|
error.response.data.error === `${inviteeId} is already in the room.`
|
||||||
|
) {
|
||||||
|
log.debug(
|
||||||
|
`User ${inviteeId} is already in room ${roomId}, probably because this user created the room as a fallback.`
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function acceptInvitation(
|
export async function acceptInvitation(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user