@@ -281,35 +281,43 @@ export class InviteApi extends TypedEmitter {
281
281
* @returns {Promise<string> }
282
282
*/
283
283
async accept ( { inviteId : inviteIdString } ) {
284
- const inviteId = Buffer . from ( inviteIdString , 'hex' )
285
-
286
- const invite = this . #invites. get ( inviteId )
287
- assert ( ! ! invite , new NotFoundError ( `Cannot find invite ${ inviteIdString } ` ) )
288
- assertCanSend ( invite . actor , { type : 'ACCEPT_INVITE' } )
284
+ try {
285
+ const inviteId = Buffer . from ( inviteIdString , 'hex' )
289
286
290
- this . #l. log ( 'Accepting invite %h' , inviteId )
291
- invite . actor . send ( { type : 'ACCEPT_INVITE' } )
292
-
293
- for ( const { value, actor } of this . #invites. values ( ) ) {
294
- if ( value . inviteId . equals ( inviteId ) ) continue
295
- const inviteIsForSameProject = value . projectInviteId . equals (
296
- invite . value . projectInviteId
287
+ const invite = this . #invites. get ( inviteId )
288
+ assert (
289
+ ! ! invite ,
290
+ new NotFoundError ( `Cannot find invite ${ inviteIdString } ` )
297
291
)
298
- if ( inviteIsForSameProject ) {
299
- actor . send ( { type : 'ALREADY_IN_PROJECT' } )
292
+ assertCanSend ( invite . actor , { type : 'ACCEPT_INVITE' } )
293
+
294
+ this . #l. log ( 'Accepting invite %h' , inviteId )
295
+ invite . actor . send ( { type : 'ACCEPT_INVITE' } )
296
+
297
+ for ( const { value, actor } of this . #invites. values ( ) ) {
298
+ if ( value . inviteId . equals ( inviteId ) ) continue
299
+ const inviteIsForSameProject = value . projectInviteId . equals (
300
+ invite . value . projectInviteId
301
+ )
302
+ if ( inviteIsForSameProject ) {
303
+ actor . send ( { type : 'ALREADY_IN_PROJECT' } )
304
+ }
300
305
}
301
- }
302
306
303
- const { projectPublicId } = await toPromise ( invite . actor )
307
+ const { projectPublicId } = await toPromise ( invite . actor )
304
308
305
- if ( ! projectPublicId ) {
306
- const { context, value } = invite . actor . getSnapshot ( )
307
- throw value === 'respondedAlready'
308
- ? new AlreadyJoinedError ( 'Already joining or in project' )
309
- : context . error || new Error ( 'Unknown error' )
310
- }
309
+ if ( ! projectPublicId ) {
310
+ const { context, value } = invite . actor . getSnapshot ( )
311
+ throw value === 'respondedAlready'
312
+ ? new AlreadyJoinedError ( 'Already joining or in project' )
313
+ : context . error || new Error ( 'Unknown error' )
314
+ }
311
315
312
- return projectPublicId
316
+ return projectPublicId
317
+ } catch ( err ) {
318
+ this . #l. log ( 'ERROR: Unable to accept invite' , err )
319
+ throw err
320
+ }
313
321
}
314
322
315
323
/**
0 commit comments