@@ -2,30 +2,56 @@ import { EventID, RoomID } from '@rocket.chat/federation-room';
22import {
33 EventAuthorizationService ,
44 InviteService ,
5+ NotAllowedError ,
56} from '@rocket.chat/federation-sdk' ;
67import { isAuthenticatedMiddleware } from '@rocket.chat/homeserver/middlewares/isAuthenticated' ;
78import { Elysia , t } from 'elysia' ;
89import { container } from 'tsyringe' ;
9- import { ProcessInviteParamsDto , RoomVersionDto } from '../../dtos' ;
10+ import {
11+ FederationErrorResponseDto ,
12+ ProcessInviteParamsDto ,
13+ ProcessInviteResponseDto ,
14+ RoomVersionDto ,
15+ } from '../../dtos' ;
1016
1117export const invitePlugin = ( app : Elysia ) => {
1218 const inviteService = container . resolve ( InviteService ) ;
1319 const eventAuthService = container . resolve ( EventAuthorizationService ) ;
1420
1521 return app . use ( isAuthenticatedMiddleware ( eventAuthService ) ) . put (
1622 '/_matrix/federation/v2/invite/:roomId/:eventId' ,
17- async ( { body, params : { roomId, eventId } , authenticatedServer } ) => {
23+ async ( { body, set , params : { roomId, eventId } , authenticatedServer } ) => {
1824 if ( ! authenticatedServer ) {
1925 throw new Error ( 'Missing authenticated server from request' ) ;
2026 }
2127
22- return inviteService . processInvite (
23- body . event ,
24- roomId as RoomID ,
25- eventId as EventID ,
26- body . room_version ,
27- authenticatedServer ,
28- ) ;
28+ try {
29+ return await inviteService . processInvite (
30+ body . event ,
31+ roomId as RoomID ,
32+ eventId as EventID ,
33+ body . room_version ,
34+ authenticatedServer ,
35+ ) ;
36+ } catch ( error ) {
37+ if ( error instanceof NotAllowedError ) {
38+ set . status = 403 ;
39+ return {
40+ errcode : 'M_FORBIDDEN' ,
41+ error :
42+ 'This server does not allow joining this type of room based on federation settings.' ,
43+ } ;
44+ }
45+
46+ set . status = 500 ;
47+ return {
48+ errcode : 'M_UNKNOWN' ,
49+ error :
50+ error instanceof Error
51+ ? error . message
52+ : 'Internal server error while processing request' ,
53+ } ;
54+ }
2955 } ,
3056 {
3157 params : ProcessInviteParamsDto ,
@@ -34,6 +60,11 @@ export const invitePlugin = (app: Elysia) => {
3460 room_version : RoomVersionDto ,
3561 invite_room_state : t . Any ( ) ,
3662 } ) ,
63+ response : {
64+ 200 : ProcessInviteResponseDto ,
65+ 403 : FederationErrorResponseDto ,
66+ 500 : FederationErrorResponseDto ,
67+ } ,
3768 detail : {
3869 tags : [ 'Federation' ] ,
3970 summary : 'Process room invite' ,
0 commit comments