From 5483004905d6bb1442766082c73190c2118164c3 Mon Sep 17 00:00:00 2001 From: juancarmore Date: Thu, 15 May 2025 21:51:54 +0200 Subject: [PATCH] backend: improve error handling for participant retrieval in LiveKit service and validate room existence in participant deletion --- backend/src/controllers/participant.controller.ts | 8 ++++++++ backend/src/services/livekit.service.ts | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/backend/src/controllers/participant.controller.ts b/backend/src/controllers/participant.controller.ts index 118fbc9..12523d0 100644 --- a/backend/src/controllers/participant.controller.ts +++ b/backend/src/controllers/participant.controller.ts @@ -73,9 +73,17 @@ export const refreshParticipantToken = async (req: Request, res: Response) => { export const deleteParticipant = async (req: Request, res: Response) => { const logger = container.get(LoggerService); + const roomService = container.get(RoomService); const participantService = container.get(ParticipantService); const { roomId, participantName } = req.params; + // Check if the room exists + try { + await roomService.getMeetRoom(roomId); + } catch (error) { + return handleError(res, error, `getting room '${roomId}'`); + } + try { logger.verbose(`Deleting participant '${participantName}' from room '${roomId}'`); await participantService.deleteParticipant(participantName, roomId); diff --git a/backend/src/services/livekit.service.ts b/backend/src/services/livekit.service.ts index 9dda4e6..1b78cd1 100644 --- a/backend/src/services/livekit.service.ts +++ b/backend/src/services/livekit.service.ts @@ -158,7 +158,7 @@ export class LiveKitService { return await this.roomClient.getParticipant(roomName, participantName); } catch (error) { this.logger.warn(`Participant ${participantName} not found in room ${roomName}: ${error}`); - throw internalError(`getting participant '${participantName}' in room '${roomName}'`); + throw errorParticipantNotFound(participantName, roomName); } }